Label text not initialising in new view iphone - iphone

DetailViewController.m
Code:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *navTitle = self.navigationItem.title;
NSString *stalklabel = self.labelforurl.text;
NSLog(#"%#", stalklabel);
NSURL *address = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.twostepmedia.co.uk/json.php?q=%#",stalklabel]];
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:address];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
//NSString *address = [NSString stringWithFormat:#"http://www.twostepmedia.co.uk/json.php?q=%#",na];
//[self initiateRequest:address];
//NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:address]];
//[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
RootViewController.m
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//Initialize the detail view controller and display it.
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
dvController.navigationItem.title=[[managedObject valueForKey:#"data"] description];
dvController.labelforurl.text = [[managedObject valueForKey:#"data"] description];
[dvController release];
dvController = nil;
}
The output of NSLOG is "Label"?? So when i try and embed it in the URL, it only comes back with "Label"??
Any ideas?

In InterfaceBuilder, or somewhere in code, your labelforurl has a value of Label. Change this value for a different result. If you want to change it in IB, use a UITextField instead of a UIlabel.

Related

Recalling viewDidLoad after failed connection not working

this is my viewDidLoad function working well :
- (void)viewDidLoad
{
[super viewDidLoad];
//iAds code
adview = [[ADBannerView alloc] initWithFrame:CGRectZero];
adview.frame = CGRectOffset(adview.frame, 0, 0);
adview.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adview.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adview];
adview.delegate = self;
self.adbanerinvesiable = NO;
//php data code
NSError *er;
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://localhost:8888/newjson.php?number=1"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
if (response.length != 0){
NSString *json_string = [[NSString alloc]initWithData:response encoding:NSUTF8StringEncoding];
listt = [parser objectWithString:json_string error:&er];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"No Internet conniction" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Refresh", nil];
[alert show];
//for ID contet post
SBJsonParser *parser2 = [[SBJsonParser alloc] init];
NSURLRequest *request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://localhost:8888/newjson.php?number=2"]];
NSData *response2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:nil error:nil];
NSString *json_string2 = [[NSString alloc]initWithData:response2 encoding:NSUTF8StringEncoding];
IDNum = [parser2 objectWithString:json_string2 error:&er];
}
}
As you can see if the connection failed it will show UIAlertView and two Buttons {ok , Refresh}.
I used this Method in case the refresh button been clicked to call viewDidLoad But not Working and giving me blank white view:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1){
[self viewDidLoad];
}
}
Any idea please ?
You should put your PHP Data Code in a method in it's own, so when you need to call that specifically you can, because you can't (or should I say shouldn't) call viewDidLoad manually. That should only be called automatically by UIViewController.
Example
- (void)viewDidLoad
{
[super viewDidLoad];
//iAds code
adview = [[ADBannerView alloc] initWithFrame:CGRectZero];
adview.frame = CGRectOffset(adview.frame, 0, 0);
adview.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adview.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adview];
adview.delegate = self;
self.adbanerinvesiable = NO;
}
-(void)viewWillAppear:(BOOL)animated /* or: -(void)viewDidAppear: */
{
[super viewWillAppear:animtaed];
[self refreshPHData];
}
-(void)refreshPHPData
{
//php data code
NSError *er;
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://localhost:8888/newjson.php?number=1"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
if (response.length != 0){
NSString *json_string = [[NSString alloc]initWithData:response encoding:NSUTF8StringEncoding];
listt = [parser objectWithString:json_string error:&er];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"No Internet conniction" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Refresh", nil];
[alert show];
//for ID contet post
SBJsonParser *parser2 = [[SBJsonParser alloc] init];
NSURLRequest *request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://localhost:8888/newjson.php?number=2"]];
NSData *response2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:nil error:nil];
NSString *json_string2 = [[NSString alloc]initWithData:response2 encoding:NSUTF8StringEncoding];
IDNum = [parser2 objectWithString:json_string2 error:&er];
}
}
Also, when you call viewDidLoad from your UIAlertView, you are creating a second (and third and so forth) adview because you aren't removing the previous instance. Depending on how many times the alert is shown and viewDidLoad is called, you are going to see adview stacking on top of itself. So try instead:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1){
[self refreshPHPData];
}
}

Passing coords of annotation Mapkit tapped

In my app, I have a set of location and their relative annotation. I have a button where cliking it, i go to a method that call a URL web service to get the google street view.
My code is:
- (NSString*)urlStreetview:(id<MKAnnotation>)annotation{
CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude];
NSLog(#"lat:%f",pinLocation.coordinate.latitude);
NSLog(#"lon:%f",pinLocation.coordinate.longitude);
NSString *lat_string = [[NSString alloc] initWithFormat:#"%f", pinLocation.coordinate.latitude];
NSString *lon_string = [[NSString alloc] initWithFormat:#"%f", pinLocation.coordinate.longitude];
NSString *url1 = [NSString stringWithFormat:#"http:myweb/streetview.php"];
NSString *url2 = [url1 stringByAppendingString: #"?lat="];
NSString *url3 = [url2 stringByAppendingString:lat_string];
NSString *url4 = [url3 stringByAppendingString:#"&lon="];
NSString *url = [url4 stringByAppendingString:lon_string];
NSLog(#"url:%#",url);
return url;
}
I wrote the previous method to have a url that is composed with the LatLong of the annotation.
I have a button called PressMe on the annotation pin. When I push it, I want to to excute the previous method, to calle the url, but I do not understand how pass the selected annotation to the streetView method.
- (IBAction)PressMe:(id)sender
{
UIViewController *webViewController = [[[UIViewController alloc] init] autorelease];
UIWebView *uiWebView = [[[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,480)] autorelease];
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: [self urlStreetview: ????]]]]; //HERE IS MY MY PROBLEM
[webViewController.view addSubview: uiWebView];
webViewController.title = #"web bar";
[self.navigationController pushViewController:webViewController animated:YES];
//[[self navigationController] pushViewController:thirdViewController animated:YES];
}
thanks in advance!
I am going to answer my question myself. I just resolve my problem an it work perfectly. The code allows to show a web view in order to have a steet View google service of the annotation map Kit annotation. Obviusly, as I am relatively new iphone developer,if someone wants to add/suggest/improve, he is welcome.
My button implementation:
- (IBAction)PressMe:(id)sender
{
UIViewController *webViewController = [[[UIViewController alloc] init] autorelease];
UIWebView *uiWebView = [[[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,480)] autorelease];
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: self.urlStreetview]]];
[webViewController.view addSubview: uiWebView];
webViewController.title = #"web bar";
[self.navigationController pushViewController:webViewController animated:YES];
//[[self navigationController] pushViewController:thirdViewController animated:YES];
}
With this button I call my (following) method "urlStreetview" the, with the annotation selected, composes a string in order to have a complet url with the apropriete GET php parameter. The url is the direction of my (very simple) web service that allow to call the google API street View.
- (NSString*)urlStreetview{
//there can only be one selected annotation so get the one at index 0
id<MKAnnotation> selectedAnnotation = [_mapView.selectedAnnotations objectAtIndex:0];
CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:selectedAnnotation.coordinate.latitude longitude:selectedAnnotation.coordinate.longitude];
//Now I have the annotation coordinate selected, so now I am able to compound the urladdingo to my base url:http://myurl/streetview.php, the GET part, I mean the lat lon coords:
NSString *lat_string = [[NSString alloc] initWithFormat:#"%f", pinLocation.coordinate.latitude];
NSString *lon_string = [[NSString alloc] initWithFormat:#"%f", pinLocation.coordinate.longitude];
NSString *url1 = [NSString stringWithFormat:#"http://myurl/streetview.php"];
NSString *url2 = [url1 stringByAppendingString: #"?lat="];
NSString *url3 = [url2 stringByAppendingString:lat_string];
NSString *url4 = [url3 stringByAppendingString:#"&lon="];
NSString *url = [url4 stringByAppendingString:lon_string];
NSLog(#"url:%#",url);
return url;
}
I hope It can be useful!

Releasing view from stack, tab bar with nav controller

So I am working on a vital update to an app I have on the appstore. I have an app with a tab bar and a nav controller. When the user selects an item from the list it sends the link it is getting from the xml file sent from my server to a detail view controller that is only a web view. The problem I'm having is when the user goes back to the tableview which is the root view for that tab the detail view isn't being released. When you select the other options in the app, the detail view doesn't change. It's not that my data isn't being released from the uishared application data but its the view isn't releasing. I know that there are many similar items like this on here and i've tried all of them. I will give you some of my code and greatly appreciate other tips and tricks. Im 15 and just getting into development so any info helps. Heres the code i think is necessary for anyone to help.
TableViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: #"link"];
// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:#" " withString:#""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:#"\n" withString:#""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:#" " withString:#""];
videoDetailViewController.title = #"Videos";
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.videoData = storyLink;
if (self.videoDetailViewController == nil)
{
VideoDetailViewController *aBookDetail = [[[VideoDetailViewController alloc] initWithNibName:#"VideosDetailView" bundle:[NSBundle mainBundle]] autorelease];
self.videoDetailViewController = aBookDetail;
[aBookDetail release];
aBookDetail = nil;
}
[self.navigationController pushViewController:videoDetailViewController animated:YES];
}
DetailViewController:
#import "VideoDetailViewController.h"
#import "RSSEntry.h"
#import "ExampleAppDataObject.h"
#import "AppDelegateProtocol.h"
#implementation VideoDetailViewController
#synthesize activityIndicator;
#synthesize webView;
#synthesize pasteboard;
- (ExampleAppDataObject*) theAppDataObject;
{
id<AppDelegateProtocol> theDelegate = (id<AppDelegateProtocol>) [UIApplication sharedApplication].delegate;
ExampleAppDataObject* theDataObject;
theDataObject = (ExampleAppDataObject*) theDelegate.theAppDataObject;
return theDataObject;
}
- (void)viewDidLoad
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
NSString *urladdress = theDataObject.videoData;
NSURL *url = [NSURL URLWithString:urladdress];
NSURLRequest *requestobj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestobj];
pasteboard = [UIPasteboard generalPasteboard];
[super viewDidLoad];
}
- (void)dealloc
{
[webView release];
webView = nil;
[activityIndicator release];
[pasteboard release];
[VideoDetailViewController release];
[urlData release];
urlData = nil;
[super dealloc];
}
#end
I skipped a lot of the code that i didnt feel was necessary. If you want the actual files then email me at evan.stoddard#me.com
Don't release the webview in the detailViewController page, instead, put
[webView loadRequest:requestobj]; in in viewDidAppear(), not viewDidLoad
Also:
One way to make the transition smoother, change:
if (self.videoDetailViewController == nil) {
VideoDetailViewController *aBookDetail = [[[VideoDetailViewController alloc] initWithNibName:#"VideosDetailView" bundle:[NSBundle mainBundle]] autorelease];
self.videoDetailViewController = aBookDetail;
[aBookDetail release];
aBookDetail = nil;
}
[self.navigationController pushViewController:videoDetailViewController animated:YES];
Should be:
VideoDetailViewController *aBookDetail = [[VideoDetailViewController alloc] initWithNibName:#"VideosDetailView" bundle:[NSBundle mainBundle]] ;
[self.navigationController pushViewController:videoDetailViewController animated:YES];
[aBookDetail release];
Thanks to Anna Billstrom, I realized that I also should be using viewDidAppear instead of viewDidLoad. This is because I am passing data to the controller through an external data class when an item is selected from the table view. Therefore, the detail view controller is loading before there is data to load from the external data class. viewDidAppear solves this problem by getting data once the view loads after the cell is selected and there is data in the external class.

Core Data text into URL for RSS iphone app

I have this code to configure a cell for Core Data:
Code:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[managedObject valueForKey:#"data"] description];
}
But what i want to do is when i click the row, here:
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
RssFunViewController *rssFun = [[RssFunViewController alloc] initWithNibName:#"RssFunViewController" bundle:nil];
//NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[self.navigationController pushViewController:rssFun animated:YES];
[rssFun release];
}
Insert the row text into the URL here:
Code:
-(BOOL)fetchAndParseRss{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
//To suppress the leak in NSXMLParser
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSURL *url = [NSURL URLWithString:#"http://news.search.yahoo.com/rss?ei=UTF-8&p=lindsay+lohan&fr=news-us-ss"];
BOOL success = NO;
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldProcessNamespaces:YES];
[parser setShouldReportNamespacePrefixes:YES];
[parser setShouldResolveExternalEntities:NO];
success = [parser parse];
[parser release];
[pool drain];
return success;
}
So where it says lindsay+lohan, i will put the users search term in here. The thing is, the 3rd piece of code is in BlogRss.m and the first two bits and in RootViewController.m?? Not sure how to make the link?? Any ideas...
Thanks
You need to pass the NSManagedObject into the incoming view controller:
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
// Navigation logic may go here -- for example, create and push another view controller.
RssFunViewController *rssFun = [[RssFunViewController alloc] initWithNibName:#"RssFunViewController" bundle:nil];
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[rssFun setSelectedObject:selectedObject];
[[self navigationController] pushViewController:rssFun animated:YES];
[rssFun release], rssFun = nil;
}
This means that your RssFunViewController needs to have a property called selectedObject which is declared as a NSManagedObject.
Then you can finish your method:
- (BOOL)fetchAndParseRss
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
//To suppress the leak in NSXMLParser
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSString *terms = [[self selectedObject] vaueForKey:#"data"];
NSURL *url = [NSURL URLWithString:[NSString stirngWithFormat:#"http://news.search.yahoo.com/rss?ei=UTF-8&p=%#&fr=news-us-ss", terms]];

tableView:didSelectRowAtIndexPath: calls TTNavigator openURLAction:applyAnimated: — UITabBar and navigationItem disappear

I have an existing iphone project with a UITabBar. Now I need styled text and in-text links to other ViewControllers in my app. I am trying to integrate TTStyledTextLabel.
I have a FirstViewController:UITabelViewController with this tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *url;
if ([self.filteredQuestions count]>0) {
url = [NSString stringWithFormat:#"%#%d", #"tt://question/", [[self.filteredQuestions objectAtIndex:indexPath.row] id]];
[[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath: url] applyAnimated:YES]];
} else {
Question * q = [self.questions objectAtIndex:indexPath.row] ;
url = [NSString stringWithFormat:#"%#%d", #"tt://question/", [q.id intValue]];
}
TTDPRINT(#"%#", url);
TTNavigator *navigator = [TTNavigator navigator];
[navigator openURLAction:[[TTURLAction actionWithURLPath: url] applyAnimated:YES]];
}
My mapping looks like this:
TTNavigator* navigator = [TTNavigator navigator];
navigator.window = window;
navigator.supportsShakeToReload = YES;
TTURLMap* map = navigator.URLMap;
[map from:#"*" toViewController:[TTWebController class]];
[map from:#"tt://question/(initWithQID:)" toViewController:[QuestionDetailViewController class]];
and my QuestionDetailViewController:
#interface QuestionDetailViewController : UIViewController <UIScrollViewDelegate , QuestionDetailViewProtocol> {
Question *question;
}
#property(nonatomic,retain) Question *question;
-(id) initWithQID:(NSString *)qid;
-(void) goBack:(id)sender;
#end
When I hit a cell, q QuestionDetailViewController will be called — but the navigationBar wont
#implementation QuestionDetailViewController
#synthesize question;
-(id) initWithQID:(NSString *)qid
{
if (self = [super initWithNibName:#"QuestionDetailViewController" bundle:nil]) {
//;
TTDPRINT(#"%#", qid);
NSManagedObjectContext *managedObjectContext = [(domainAppDelegate*)[[UIApplication sharedApplication] delegate] managedObjectContext];
NSPredicate *predicate =[NSPredicate predicateWithFormat:#"id == %#", qid];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Question"
inManagedObjectContext:managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *array = [managedObjectContext executeFetchRequest:request error:&error];
if (error==nil && [array count]>0 ) {
self.question = [array objectAtIndex:0];
} else {
TTDPRINT(#"error: %#", array);
}
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[TTStyleSheet setGlobalStyleSheet:[[[TextTestStyleSheet alloc] init] autorelease]];
[self.navigationController.navigationBar setTranslucent:YES];
NSArray *includedLinks = [self.question.answer.text vs_extractExternalLinks];
NSMutableDictionary *linksToTT = [[NSMutableDictionary alloc] init];
for (NSArray *a in includedLinks) {
NSString *s = [a objectAtIndex:3];
if ([s hasPrefix:#"/answer/"] || [s hasPrefix:#"http://domain.com/answer/"] || [s hasPrefix:#"http://www.domain.com/answer/"]) {
NSString *ttAdress = #"tt://question/";
NSArray *adressComps = [s pathComponents];
for (NSString *s in adressComps) {
if ([s isEqualToString:#"qid"]) {
ttAdress = [ttAdress stringByAppendingString:[adressComps objectAtIndex:[adressComps indexOfObject:s]+1]];
}
}
[linksToTT setObject:ttAdress forKey:s];
}
}
for (NSString *k in [linksToTT allKeys]) {
self.question.answer.text = [self.question.answer.text stringByReplacingOccurrencesOfString:k withString: [linksToTT objectForKey:k]];
}
TTStyledTextLabel *answerText = [[[TTStyledTextLabel alloc] initWithFrame:CGRectMake(0, 0, 320, 700)] autorelease];
if (![[self.question.answer.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] hasPrefix:#"<div"]) {
self.question.answer.text = [NSString stringWithFormat:#"%<div>%#</div>", self.question.answer.text];
}
NSString * s = [NSString stringWithFormat:#"<div class=\"header\">%#</div>\n%#",self.question.title ,self.question.answer.text];
answerText.text = [TTStyledText textFromXHTML:s lineBreaks:YES URLs:YES];
answerText.contentInset = UIEdgeInsetsMake(20, 15, 20, 15);
[answerText sizeToFit];
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self.view addSubview:answerText];
[(UIScrollView *)self.view setContentSize:answerText.frame.size];
self.view.backgroundColor = [UIColor whiteColor];
[linksToTT release];
}
.......
#end
This works quite nice, as soon as a cell is touched, a QuestionDetailViewController is called and pushed — but the tabBar will disappear, and the navigationItem — I set it like this: self.navigationItem.title =#"back to first screen"; — won't be shown. And it just appears without animation.
But if I press a link inside the TTStyledTextLabel the animation works, the navigationItem will be shown.
How can I make the animation, the navigationItem and the tabBar be shown?
I found a solution:
My QuestionDetailViewController implements the TTNavigatorDelegate.
-(BOOL)navigator:(TTNavigator *)navigator shouldOpenURL:(NSURL *)URL will always return NO, but will call [self.navigationController pushViewController:c animated:YES];
-(BOOL)navigator:(TTNavigator *)navigator shouldOpenURL:(NSURL *)URL {
NSEntityDescription *entity;
NSPredicate *predicate;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
if ([[URL host] isEqualToString:#"question"]) {
entity =[NSEntityDescription entityForName:#"Question" inManagedObjectContext:managedObjectContext];
predicate = [NSPredicate predicateWithFormat:#"id == %#", [[URL path] stringByReplacingOccurrencesOfString:#"/" withString:#""]];
[request setEntity:entity];
[request setPredicate:predicate];
NSError *error =nil;
NSArray *array = [managedObjectContext executeFetchRequest:request error:&error];
if (error==nil && [array count] >0) {
QuestionDetailViewController *c = [[[QuestionDetailViewController alloc] init] autorelease];
c.question = [array objectAtIndex:0];
[self.navigationController pushViewController:c animated:YES];
}
}
[request release];
return NO;
}
In your TableViewController, add:
- (id<UITableViewDelegate>)createDelegate {
return self;
}
Then you can implement your own didSelectRowAtIndexPath and accessoryButtonTappedForRowWithIndexPath methods.