Ios 详细的情节提要,其中3个已发布
正如在详细故事板的Xcode中实现的,根据id,发布了带有Tableview的3。 表hav Name和Id中的行(int值)Ios 详细的情节提要,其中3个已发布,ios,xcode,uitableview,storyboard,detailview,Ios,Xcode,Uitableview,Storyboard,Detailview,正如在详细故事板的Xcode中实现的,根据id,发布了带有Tableview的3。 表hav Name和Id中的行(int值) 我使用序列图像板中的导航控制器您需要将ViewController添加到序列图像板,使其序列图像板ID与其名称相同 创建一个dataSourceArray,它将保存具有Id和Name值的字典对象 #define kItemId @"Id" #define kItemTitle @"Name" - (void)viewDidLoad { [super view
我使用序列图像板中的导航控制器您需要将ViewController添加到序列图像板,使其序列图像板ID与其名称相同 创建一个dataSourceArray,它将保存具有Id和Name值的字典对象
#define kItemId @"Id"
#define kItemTitle @"Name"
- (void)viewDidLoad
{
[super viewDidLoad];
self.dataSourceArray = @[@{kItemId: @1,kItemTitle:@"First"},
@{kItemId: @2,kItemTitle:@"Second"},
@{kItemId: @3,kItemTitle:@"Third"}];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = self.dataSourceArray[indexPath.row][kItemTitle];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dict = self.dataSourceArray[indexPath.row];
NSUInteger tag = [dict[kItemId]integerValue];
NSString *identifier = nil;
switch (tag) {
case 1:
{
identifier = @"OneViewController";
break;
}
case 2:{
identifier = @"TwoViewController";
break;
}
case 3:{
identifier = @"ThreeViewController";
break;
}
default:
break;
}
UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
viewController.title = identifier;
[self.navigationController pushViewController:viewController
animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
太好了,但问题在哪里?谢谢你的帮助。现在,在没有seque作为详细视图中给定变量的情况下出现了一个新问题。@PetroNepyivoda抱歉,您可以重新表述您的问题吗?我想将wariable从ViewController传输到DETAILVIEW,就像seque ONEVIEWCOLLER*detail=[????????];detail.Name=self.dataSourceArray[indexath.row][kItemTitle];-例如,在OneViewController@property(非原子,保留)NSString*名称中@PetroNepyivoda现在我知道了,您可以在switch语句中移动viewController的实例化。你能说说你想要分配的具体数据是什么吗?
#define kItemId @"Id"
#define kItemTitle @"Name"
- (void)viewDidLoad
{
[super viewDidLoad];
self.dataSourceArray = @[@{kItemId: @1,kItemTitle:@"First"},
@{kItemId: @2,kItemTitle:@"Second"},
@{kItemId: @3,kItemTitle:@"Third"}];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = self.dataSourceArray[indexPath.row][kItemTitle];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dict = self.dataSourceArray[indexPath.row];
NSUInteger tag = [dict[kItemId]integerValue];
NSString *identifier = nil;
switch (tag) {
case 1:
{
identifier = @"OneViewController";
break;
}
case 2:{
identifier = @"TwoViewController";
break;
}
case 3:{
identifier = @"ThreeViewController";
break;
}
default:
break;
}
UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
viewController.title = identifier;
[self.navigationController pushViewController:viewController
animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}