2
我想在Xcode 4.2上創建一個UITableView應用程序。 我只是希望每個細胞(例如,卡利)推新視圖控制器時,其推如何從UITableView對象單元中推新的視圖控制器
我遇到的問題是每當我按下它不是推新視圖控制器
MY TableViewController細胞。^h
#import <UIKit/UIKit.h>
@interface Adam : UITableViewController
{
NSMutableArray *states;
}
@end
我Tableviewcontroller.m
#import "Adam.h"
#import "ViewController.h"
@implementation Adam
- (void)viewDidLoad
{
[super viewDidLoad];
states = [NSMutableArray arrayWithObjects:
@"cali",
@"ohio",
nil];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [states 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];
}
UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
[cellLabel setText:[states objectAtIndex:indexPath.row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([[states objectAtIndex:indexPath.row] isEqual:@"cali"])
{
ViewController *cali = [[ViewController alloc] initWithNibName:@"cali" bundle:nil];
[self.navigationController pushViewController:cali animated:YES];
}
}
@end
你遇到什麼問題?如果你在didSelectRowAtIndexPath中設置了一個斷點,它會到達那裏嗎? – 2012-01-02 20:19:50
抱歉不清楚。但我只是更新了我的問題 – 2012-01-03 02:23:46
np。那麼它進入'didSelectRowAtIndexPath'方法嗎? – 2012-01-03 02:30:54