UITableView and didSelectRowAtIndexPath issue - iphone

I have a UITableView populated with a location-based datasource. I'm calling [self updateView]; to manually refresh the view after the location is found which works fine...but for some reason the didSelectRowAtIndexPath method isn't getting called. Any ideas of why it's not working?
Code snippet: http://pastie.org/464300

Ensure that the delegate property of your tableView is set.
slf said:
Make sure it's defined in your .h
file. The protocol does a
'doesRespondToSelector' first and if
you aren't making it public through
your header the message my fail
-respondsToSelector: will detect methods that are not exposed in the interface.

Related

NSKeyedUnarchiver + UITableViewController not functioning correctly

I am attempting to use NSKeyedArchiver to store the state of my UITabBarController. Inside the tabs are UINavigationControllers which contain UITableViewControllers.
The archiving appears to work without any problem.
When unarchiving I am running into strange problems with my UITableViewControllers. initWithCoder: is called correctly, and the first thing I am doing inside there is calling [super initWithCoder:]
The tableView appears to be correctly recreated, and has a delegate and dataSource property already set. If my initWithCoder: does nothing but call super and return self then my table view ends up empty and my delegate methods are not called. If I hookup the delegate and dataSource properties of self.tableView I see my content correctly, but didSelectRowAtIndexPath is not called upon selecting, and in one instance I am unable to scroll until the tableView is reloaded.
If in initWithCoder: I create a new UITableView everything works but I don't believe I should need to do this.
Am I doing something I shouldn't be in attempting this, or am I missing something obvious that I need to add to get things working correctly?
Update: setting self.tableView = [decoder decodeObjectForKey:#"tableView"] inside my controller seems to solve the scroll/select problem, but the resulting tableView is always UITableViewStylePlain and still seems like the wrong thing to do as the property is already set.
Your design pattern is certainly unusual. Normally, you wouldn't try to archive the table view, just the data used to create it. Then when you need the table view again, you would recreate it from those data, using the same code you used to create it in the first place.

UITableView not populating in Tab bar iPhone application

I have a tab bar application which loads a UITableView when one of it's buttons are selected. It seems to load the view controller however it doesn't seem to be populating the data. I have tried setting the cell.text = #"cell" (while setting the number of rows > 0) and an NSLog in the CellForRowAtIndexPath proves that in fact the function is not being called. The same NSLog output to the console in the viewDidLoad function also generates no output so it seems as though its not getting called.
Any suggestions?
Try and call [tableView reloadData] from your -(void)viewWillAppear:(BOOL)animated; method. This should be called each time the user navigates to that tab and should set off the delegate callbacks that aren't currently being called. If they still aren't called make sure you have set the table delegate to self.
EDIT: Actually make sure you have set your table view's delegate and datasource to self;

How to access delegate returned parameters outside of the delegate method?

I've got a UIViewController with a UIPicker on it and I've got the - (void)sourcePickerViewController:(SourcePickerViewController *)controller etc... which returns several bits of data (the etc...) to it's delegate. Inside the delegate method, I see the values I want and can output them via NSLog but I can't figure out how to use them elsewhere in the code. In the same UIViewController that has that delegate method in it, I have another method that should update some UITextFields based on the data returned, but I get errors like dataVariableName undeclared.
Any suggestions?
When the delegate method is called store references to the variables in your delegate class, then you will be able to use them in other methods.

Must I call super when I implement -scrollViewDidScroll: of UIScrollViewDelegate in an UITableView?

I made a custom UITableView subclass and implemented this:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// scrolled...
}
Now, what I think is that UITableView may also love to get this message for some obvious reasons. However, when I don't forward that to super, for some reason, everything still works fine. Must I forward that guy to super? I mean...it's a delegate method implementation, but as far as I'm aware of, this would still override anything implemented in UITableView, or not?
Edit: I see...the delegate could be anyone. Never mind about this. BUT: What I have such a thing in a superclass, and make a subclass. How would I even know that the superclass does implement that method and I must forward it to super?
Short answer: no.
Those methods are defined in the UIScrollViewDelegate Protocol.
They are meant to be implemented in a delegate, which maybe only has NSObject as parent.
It does not override anything, as it's a delegate method.
The UIScrollView just does it's stuff, and calls the delegate method if a delegate is set.
This is a delegate method which means it gets called by your instance of UITableView for your convenience.
The scrolling happens and the UITableView internal code will call.
if ([delegate respondsTo:#selector(scrollViewDidScroll:)]) {
[delegate performSelector:#selector(scrollViewDidScroll:) withObject:[self scrollView]];
}
And so you use this method to implement additional functionality, for example activating a control when the tableView has scrolled a certain amount.
Hope this helps!

iphone - UIWebView Problem

I have created a nib file and added a UIWebView. i created an IBOutlet and attached web view with that outlet. till here everything is fine . now when i set the delegate of that webview to self in ViewDidLoad, and implement two of its delegate methods. the application crashes, i m not writing anything in the methods , i have just implemented and the application is crashing ....
what could b the problem ?
is there any problem ???
There is a problem if one of the delegate methods is
– webView:shouldStartLoadWithRequest:navigationType:
Indeed, this method returns a BOOL (YES if the web view should begin loading content; otherwise, NO). Therefore, since you are not writing any code inside the method, this may cause a problem. Try inserting in this method the statement
return YES;
The other delegate methods return void, so these should not be the cause of the problem.