0

我已经在我的项目中实现了本教程,但是表格没有显示右侧的箭头并单击进入详细视图,而是占据了整个视图(甚至在状态栏上)并且不显示箭头或推入. 是因为我使用的标签栏吗?我以编程方式将其放入 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;
}

这是我得到的看法。 它仍然滚动等

4

2 回答 2

1

2 件事。

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

  2. 对于与顶栏重叠的表格视图,请使用它来避免它

    viewController.edgesForExtendedLayout = UIRectEdgeNone;

对于 self.Window 部分,您的 didFinishLoadingWithOptions 应该如下所示

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
[self.window setRootViewController:tbc]; //tab bars
于 2014-03-26T16:43:47.437 回答
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;
于 2014-03-26T17:09:57.107 回答