2014-03-26 216 views
0

我已經在我的項目中實現了this tutorial,但不是顯示右側的箭頭並單擊detailview,表佔用整個視圖(甚至在狀態欄上)以及不顯示箭頭或穿過。是否因爲我使用的標籤欄?我把這個以編程方式放在appdelegate文件中。表視圖不顯示詳細視圖

我tableviewcontroller.m

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
self.tableView.delegate = self; 
self.tableView.dataSource = self; 
[self makeRestuarantRequests]; 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

-(void)makeRestuarantRequests 
{ 
NSURL *url = [NSURL  URLWithString:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=restuarants+in+greenwich&sensor=false&key=AIzaSyD-kWneJACswSQfMFQ7sxRPhAEZpHHgvnw"]; 

NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
//AFNetworking asynchronous url request 
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; 

operation.responseSerializer = [AFJSONResponseSerializer serializer]; 
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id  responseObject) { 

    self.googlePlacesArrayFromAFNetworking = [responseObject objectForKey:@"results"]; 

    NSLog(@"The Array: %@",self.googlePlacesArrayFromAFNetworking); 

    [self.tableView reloadData]; 


} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 

    NSLog(@"Request Failed: %@, %@", error, error.userInfo); 

}]; 

[operation start]; 

} 



#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 

// Return the number of sections. 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

// Return the number of rows in the section. 
return [self.googlePlacesArrayFromAFNetworking count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if(cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 


NSDictionary *tempDictionary= [self.googlePlacesArrayFromAFNetworking objectAtIndex:indexPath.row]; 

cell.textLabel.text = [tempDictionary objectForKey:@"name"]; 

if([tempDictionary objectForKey:@"rating"] != NULL) 
{ 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"Rating: %@ of 5",[tempDictionary objectForKey:@"rating"]]; 
} 
else 
{ 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"Not Rated"]; 
} 

return cell; 
} 


#pragma mark - Prepare For Segue 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
ViewController *detailViewController = (ViewController *)segue.destinationViewController; 
detailViewController.restaurantDetail = [self.googlePlacesArrayFromAFNetworking objectAtIndex:indexPath.row]; 
} 

@end 

我的appdelegate文件(標籤欄的東西)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
// Override point for customization after application launch. 

//Add tab bar 
UITabBarController *tbc = [[UITabBarController alloc]init]; 

//Specify viewcontrollers for each tab 
MapViewController *mvc = [[MapViewController alloc]init]; 
TableViewController *evc = [[TableViewController alloc]init]; 
AboutViewController *avc = [[AboutViewController alloc]init]; 

//Label for tabs 
[mvc.tabBarItem setTitle:@"Map"]; 
[evc.tabBarItem setTitle:@"Eat"]; 
[avc.tabBarItem setTitle:@"About"]; 

[mvc.tabBarItem setImage:[UIImage imageNamed:@"103-map.png"]]; 
[evc.tabBarItem setImage:[UIImage imageNamed:@"125-food.png"]]; 
[avc.tabBarItem setImage:[UIImage imageNamed:@"28-star.png"]]; 

[tbc setViewControllers:[NSArray arrayWithObjects:mvc, evc, avc, nil]]; 


//Add the view controller's view to the window and display. 
[self.window addSubview:viewController.view]; 
[self.window makeKeyAndVisible]; 
[self.window setRootViewController:tbc]; //tab bars 

return YES; 
} 

This is the view I get. It still scrolls etc

回答

1

除了nsuinteger的回答,有問題的表格單元格的detailLabel是你沒有指定正確的風格表格視圖單元格:

// default style 
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

想要UITableViewCellStyleSubtitle樣式化的單元格和您的概率布萊也想設置accessoryType屬性,也爲披露指標:

// subtitle style 
cell = [[[UITableViewCell alloc] UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
+0

這有助於我的風格,謝謝!但它仍然沒有通過我的detailView。我也檢查了所有連接 – user1336868

+0

推進到詳細視圖可能與你的賽格有關,這應該是一個單獨的問題。 – Aaron

1

兩件事情。

  1. 您的didFinishLoadingWithOptions方法看起來很奇怪。你添加到self.Window中的視圖控制器在哪裏?這條線>>[self.window addSubview:viewController.view];如果你使用故事板我不明白爲什麼你做這個的appdelegate ...

  2. 對於實現代碼如下重疊頂級酒吧利用這一點避免它

    viewController.edgesForExtendedLayout = UIRectEdgeNone;

您didFinishLoadingWithOptions應該是這樣的self.Window部分

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
[self.window makeKeyAndVisible]; 
[self.window setRootViewController:tbc]; //tab bars 
+0

做我把'viewController.edgesForExtendedLayout = UIRectEdgeNone;'在viewDidLoad中?並且我更改viewController部分,因爲xCode不喜歡它! – user1336868

相關問題