表视图没有显示详细视图

时间:2014-03-26 16:39:55

标签: ios uitableview uitabbarcontroller detailview

我已将this tutorial实施到我的项目中,但不是在右侧显示箭头并点击详细视图,而是占用整个视图(甚至在状态栏上)不显示箭头或推动。是因为我使用的标签栏吗?我以编程方式将其放在appdelegate文件中。

my 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

2 个答案:

答案 0 :(得分:1)

2件事。

  1. 你的didFinishLoadingWithOptions方法看起来很奇怪。您添加到self.Window中的视图控制器在哪里?这一行>> [self.window addSubview:viewController.view];如果您使用的是故事板,我不明白为什么要在appdelegate上执行此操作...

  2. 对于与顶部栏重叠的tableview,使用此选项来避免它

    viewController.edgesForExtendedLayout = UIRectEdgeNone;

  3. 你的didFinishLoadingWithOptions对于self.Window部分应该是这样的

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

答案 1 :(得分: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;