Learning Objective-C and reading sample code, I notice that objects are usually created using this method:
SomeObject *myObject = [[SomeObject alloc] init];
instead of:
SomeObject *myObject = [SomeObject new];
Is there a reason for this, as I have read that they are equivalent?
...
hi, i got a problem with the following codes:
NSString *strValue=@"你好";
char temp[200];
strcpy(temp, [strValue UTF8String]);
printf("%s", temp);
NSLog(@"%s", temp);
in the first line of the codes, two Chinese characters are double quoted. The problem is printf function can display the Chinese characters properly, but NSLog can't.
...
I'm using DarwiinRemote's WiiRemote.framework in my app.
I already fixed some issues by downloading the source code and requiring garbage collection, and building for 10.5. However, when I try to add it to my project, I get the console error:
dyld: Library not loaded: @executable_path/../Frameworks/WiiRemote.framework/Versions/A/WiiRe...
I am working through the Stanford iPhone class and I can't figure out why I am getting a compiler warning. I assume I need to cast my object to NSString, but I get an error when I try to do so. The code runs and gives me the expected output, but the warning bothers me.
NSLog(@"lowerCaseString is: %@", [object lowercaseString]);
This r...
I am creating a modal view which is opened using the following code
[[self navigationController] presentModalViewController:registrationController animated:NO];
And until recently the following code was used to hide it on a button press
[self dismissModalViewControllerAnimated:YES];
However for some reason that line is no longer re...
I previously used the following code for changing the size of my cells which use a custom tableviewcell
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 61;
}
However I've created a new one on a different view and the above code is never being called.
The TableViewCell is actu...
I have read several of the post about Objective-C method syntax but I guess I don't understand multiple names for a method.
I'm trying to create a method called getBusStops with NSString and NSTimeInterval parameters and a return type of NSMutableArray. This is how I have constructed the method but it obviously gets errors at runtime:
...
I have the following method that should populate the cells of my UITableView with data from an array. I want to get the data from the array using the row that the data is being loaded into as the index.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cellComments=(FullCommentC...
I have a calling method that looks like the following:
-(void)callingMethod
{
NSMutableString *myStr = [[[NSMutableString alloc] initWithCapacity:0] autorelease];
myStr = [self calledMethod];
}
And my called method:
-(NSMutableString*)calledMethod
{
NSMutableString *newStr = [[NSMutableString alloc] initWithCapacity:0];...
Apple's sample app named Reachability shows how to detect connections. If you have only wifi but not internet, the app stalls for over a minute on the second line below:
SCNetworkReachabilityFlags reachabilityFlags;
BOOL gotFlags = SCNetworkReachabilityGetFlags(reachabilityRef, &reachabilityFlags);
SCNetworkReachabilityGetFlags comes...
The following method loads data from an array into custom cells of UITableView. The data is loaded in correctly. However, when I scroll down data in the above cells (the cells not visible) are changed to seemingly random elements in the array.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *...
I'm curious what some reasons might be as to getting a compiler error for simply importing a header file. If I comment it out, everything compiles just fine -- the header/implementation for the class I'm trying to import into one of my UIViewController's get passed the compiler without any warnings. However, as soon as I include it, I ge...
The property label is of type UILabel and is an outlet in UIViewController.
Why does the following work :-
[window addSubview:viewController.view];
[viewController.label setText:@"New Label"] ;
and the reverse sequence of statements doesn't change the default text in the label:
[viewController.label setText:@"New Label"] ;
[window ...
I want to convert NSData to a byte array, so I write the following code:
NSData *data = [NSData dataWithContentsOfFile:filePath];
int len = [data length];
Byte byteData[len];
byteData = [data bytes];
But the last line of code pops up an error saying "incompatible types in assignment".
What is the correct way to convert the data to by...
Is it possible to make simultaneously two requests in parallel to the same server using NSURLConnection?
I'm trying to do it, and it looks like the second request do not start until the first one finishes.
...
Hi,
I have another question about restoring application state, on the iPhone.
Simple data (like the selected tab) can be stored in NSUserDefaults, but it is not enough.
I want to restore the whole state, including the Navigation Controllers (go to the sub-sub-sub View Controller).
My problem is that my application is divided in severa...
How can I remove this "could not find audio decoder component 64766938 for registration" which is shown in nslog?
...
Hi, how can I modify a 2d array in objective c? I need to create a mutable one.
For example I have:
NSMutableArray *sections;
NSMutableArray *rows;
Each item in sections consists of array rows. Rows is an array that contains objects.
And I want to do something like this:
[ sections[i] addObject: objectToAdd]; //I want to add a new ...
Hi,
In my table view I have to scroll to the top. But I cannot guarantee that the first object is going to be section 0, row 0. May be that my table view will start from section number 5.
So I get an exception, when I call:
[mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewSc...
Hey guys,
I have a UIWebView in my app that is used to show webpages of links clicked within my app.
Some of the links are URL-Shortened links, such as tinyURL or bit.ly. These url's redirect after the initial url load.
My problem is that some of the links in my app are URL-Shortened links to resources that are not webpages - such as ...