0
Xcode 4.2에서 UITableView
응용 프로그램을 만들려고합니다. 각 세포 (예 : Cali)가 만졌을 때 새로운 UIViewController
을 누르기 만하면됩니다.UITableView 셀에서 새보기 컨트롤러를 푸시 할 수 없습니다.
내가 겪고있는 문제는 셀을 누를 때마다 새 뷰 컨트롤러를 밀고 있지 않다는 것입니다.
didSelectRowAtIndexPath
메서드에 중단 점을 넣으면 5 개의 스레드가 나타납니다. 당신이 당신의 자신의 레이블을 만들 필요가 없습니다
#import <UIKit/UIKit.h>
@interface Adam : UITableViewController
{
NSMutableArray *states;
}
@end
#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