How to group methods belong to one entity in one class file in Core Data like Linq? In Linq, we can put all methods in the domain object class and reuse them, in Core Data, is there any way to create different classes for different entities? Or we can only use predicate to retrieve?
I have a 'Contact' class with two properties : firstName and lastName.
When I want to display a contact's full name, here is what I do:
NSString *fullName = [NSString stringWithFormat:@"%@ %@", contact.firstName, contact.lastName];
But when the firstName and/or lastName is set to nil, I get a "(null)" in the fullName string. To prevent it, here's what I do:
NSString *first = contact.firstName;
if(first == nil) first = @"";
NSString *last = contact.lastName;
if(last == nil) last = @"";
NSString *fullName = [NSString stringWithFormat:@"%@ %@", first, last];
Does someone know a better/more concise way to do this?
I have created View A and View B. My window has View A displayed on the screen. I also have a UIButton on View A. I want to switch from View A to View B when I click on the Button. I am not using any UIViewController. Is it possible to switch the views without using controller?
I am calling buttonAction method on TOUCHUPINSIDE
The problem is that it doesn't do anything when I say
[ViewA removeFromSuperView];
What should I do now?
Hi i am developing an app for my QA department. I need to programically get how many phone numbers are there in the entire address book. No user input. Just click a button and then get how many phonenumbers are there in the ENTIRE addressbook.
Please email me at [email protected]
I am trying to authenticate using the below code
NSString *urlAsString =[NSString stringWithFormat:@"http://www.myurl.com/abc/authenticate.php"];
NSURL *url = [NSURL URLWithString:urlAsString];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setTimeoutInterval:30.0f];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest addValue:@"test" forHTTPHeaderField:@"m_username" ];
[urlRequest addValue:@"123" forHTTPHeaderField:@"m_password" ];
[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response,NSData *data, NSError *error) {
if ([data length] >0 && error == nil){
html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"HTML = %@", html);
receivedData = [NSMutableData data];
}
else if ([data length] == 0 && error == nil){
NSLog(@"Nothing was downloaded.");
}
else if (error != nil){
NSLog(@"Error happened = %@", error);
}
}];
// Start loading data
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if (theConnection)
{
// Create the NSMutableData to hold the received data
receivedData = [NSMutableData data];
}
else {
// Inform the user the connection failed.
}
My username password is correct, I think I am not making the proper call thats why I dont get the desired results and the web service is receiving the null parameters.
What can be the issue?
Any help appreciated.
Note: Using Monotouch. I have a directory called Images where I have all my PNG files. In my code I have the following
_imgMinusDark = UIImage.FromFile("images/MinusDark.png");
On the simulator it runs fine, on the phone it's null. I have the Images folder content (all the PNGs) in my MonoDevelop marked as Content in terms of Build Action.
What am I missing?
thanks
I found some sample code from here.
static UIImage *backgroundImageDepressed;
/**
*
*/
@implementation DecimalPointButton
+ (void) initialize {
backgroundImageDepressed = [[UIImage imageNamed:@"decimalKeyDownBackground.png"] retain];
}
is it something like this - +(void) initialize method initialize static variables of a class ( interface ) in objective c ? I have never seen this before.
Please need your guidance on it.
Thanks in advance for sharing your great knowledge.
Sagar
Hi,
I need to extract the detail content of a website while preserve all formatting of the division. The section I wish to extract is:
...
<div class="detailContent"><p>
<P dir=ltr><STRONG>Hinweis</strong>: Auf ... </p>
</div>
...
My current solution is to use HTMLParser from libxml2 and xpath to find the nodes and walk through all the nodes to reconstruct this piece of HTML. This is a long an complicated code.
I' just wondering if there is an easier solution to extract part of HTML?
Thanks.
I've done some reorganizing of my project recently and now I'm not seeing my tab bar controller, but its first view controller's view is appearing. Here's a breakdown of everything that happens prior to the problem.
App Delegate loads FirstViewController with nib. FirstViewController loads the application data from my server and then presents MainViewController with a modal transition. MainViewController is where the UITabBarController is supposed to be appearing. It's a very simple class.
The .h
@interface MainViewController : UIViewController <UITabBarControllerDelegate> {
IBOutlet UITabBarController *tabBarController;
}
@property (nonatomic, retain) UITabBarController *tabBarController;
@end
The .m
@implementation MainViewController
@synthesize tabBarController;
- (void)viewDidLoad {
NSLog(@"MainViewController viewDidLoad");
//set tab bar controller delegate to self
tabBarController.delegate = self;
// home view
HomeViewController *home = [[HomeViewController alloc] initWithTab];
// menu view
MenuViewController *menu = [[MenuViewController alloc] initWithTab];
// special offers view
SpecialOffersViewController *so = [[SpecialOffersViewController alloc] initWithTab];
// events view
EventsViewController *events = [[EventsViewController alloc] initWithTab];
// info view
InfoViewController *info = [[InfoViewController alloc] initWithTab];
//populate the tab bar controller with view controllers
NSArray *controllers = [NSArray arrayWithObjects:home, menu, so, events, info, nil];
tabBarController.viewControllers = controllers;
//release view controllers
[home release];
[menu release];
[so release];
[events release];
[info release];
[controllers release];
//add tab bar controller to view
[self.view addSubview:tabBarController.view];
[super viewDidLoad];
}
and here's the bit from FirstViewController that modally presents the MainViewController...
MainViewController *controller = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
I'm not getting any compiler errors or warnings and the app runs swell... no crashing. It just isn't showing the darned TabBar, and it used to when I was creating it on my AppDelegate. I checked everything in my NIB and my outlets seem to be hooked up ok. I have no idea what's happened. Help!
I have a class with a method that works and I have tested it but xcode still raises a warning over the method:
MapPoint *mp = [[MapPoint alloc] initWithCoordinate:[newLocation coordinate] title:[locationTitleField text]];
no 'initWithCoordinate:title' method found?
Hi..
I am having a table view with default UITableViewCell of style UITableViewCellStyleValue2. I just want to move detailTextLabel few pixels to the right. I know it makes no sense to adjust its width and height :). I am trying to set detailTextLabel's frame with my x and y value. But its not affecting the its frame. I prefer to use default UITableViewCell, in this case, over a customized cell because the default UITableViewCell automatically manages the text alignment and centering of the labels..
How to change UITableViewCell detailTextLabel's frame?
Am I allowed to change its frame?
Thanks everyone..
Hi all!
I've search for some clues on this problem without much success. Hope someone can kick me in the right direction.
I am prototyping a couple of apps where I need to design my own GUI. The GUI is made up by two separated UIViews where one of them contains a small thumb of an image. I want to be able to drag this thumb from the first view to the other. Simple as that! But I haven't figured out how this is done. Here is the exact flow I am looking for:
touch the thumb
animate a small enlargement of the thumb
drag the thumb to the other UIView
drop the thumb
animate a shrink of the thumb
Not particularly strange, but the thumb remains related to the first view all the time. I've tried to move the thumb via the first views superview and then back to the second view, but with no luck.
Hello All,
Iam trying to saving an UIImage in PDF file.
How can i do this? How i would save and image into pdf file and then export that pdf file?
Please suggest the solution for the issue i faced.
Thank You.
I wonder in which cases it would be good to make an NSManagedObjectModel completely programmatically, with NSEntityDescription instances and all this stuff.
I'm that kind of person who prefers to code programmatically, rejecting Interface Builder. But when it comes to Core Data, I have a hard time figuring out why I should kill my time NOT using the nice Xcode Data Modeler tool.
And since data models are stuck to a given state (except when you want to do some ugly migration operations where thinks probably go wrong and users get mad, really mad), I see no big sense in a data model that's made programmatically for the purpose of changing it all the time.
Did I miss something?
I want to create two UIViews in quartz 2D application.
First UIView for static text, it will redraw automatically after each one second.
Second UIView for animated text, it will be redrawn automatically after each .1 second.
How can i create multiple Views/Layers? Is there drawRect methods will be different?
Hi
I want to replace my UIBarButtonItem (used for refresh) with a UIAlertView and, when the refresh is finished, I want to turn back to the refresh button and remove the UIAlertView. Can anyone help me?
Thanks
Coming from a C++ background, one thing that confuses me about Objective C is the fact that you can add a method to a class without actually specifying it in the class interface. So I had a barrage of questions:
Why would someone choose to not add the method in the class interface?
Is it simply because of visibility?
Methods without a declaration in the interface are private?
Is declaring methods in a class interface just optional?
Is it different for overriding a base class' method?
I want add days to a date, I got many codes for this but none of them are working for me below shown is my code,please somebody help me to fix this issue
int daysToAdd=[[appDlegateObj.selectedSkuData
objectForKey:@"Release Time"] intValue];
NSTimeInterval secondsForFollowOn=daysToAdd*24*60*60;
NSString *dateStr=[contentDic objectForKey:@"Date"];
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *dateFromString=[[NSDate alloc]init];
dateFromString=[dateFormatter dateFromString:dateStr];
[dateFormatter release];
NSDate *date=[dateFromString dateByAddingTimeInterval:secondsForFollowOn];
I have a problem with my UIScrollView. It's visible but I can't scroll it.
CGRect frame = CGRectMake(20, 90,280,1000);
scroll1=[[UIScrollView alloc]initWithFrame:frame];
scroll1.contentSize = CGSizeMake(280,1000);
scroll1.backgroundColor=[UIColor grayColor];
//scroll1.delegate=scroll1;
[scroll1 setUserInteractionEnabled:TRUE];
[scroll1 setPagingEnabled:TRUE];
[scroll1 setScrollEnabled:TRUE];
[scroll1 showsVerticalScrollIndicator];
Thanks in advance.
So I call this method:
-(void)beginExecution {
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(execute)
object:nil];
[queue addOperation:operation];
[operation release];
}
Which triggers this:
-(void)execute {
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@"MyTexture.plist"];
loaded = YES; // This tells me whenever loading is done.
}
However, when I create a sprite and try to use the texture MyTexture.png, the sprite is a blank canvas. Why is that?