Ios 自定义UITableView-iphone
我使用了Ios 自定义UITableView-iphone,ios,objective-c,uitableview,uinavigationcontroller,Ios,Objective C,Uitableview,Uinavigationcontroller,我使用了UITableView并构建了customCell,UITableView连接到NavigationController 我希望单元格1-3使用导航栏(例如,单击单元格传递到下一个视图) 单元格4-5保持为可单击单元格(例如,我单击此单元格,单元格背景会发生变化) 在情节提要中,标识符等于单元格。 现在任何行动都会把我转到另一个角度,有人能帮我吗 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtInde
UITableView
并构建了customCell
,UITableView
连接到NavigationController
我希望单元格1-3使用导航栏
(例如,单击单元格传递到下一个视图)
单元格4-5保持为可单击单元格(例如,我单击此单元格,单元格背景会发生变化)
在情节提要中,标识符等于单元格
。
现在任何行动都会把我转到另一个角度,有人能帮我吗
-(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];
}
return cell;
}
您可以为此使用(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath
方法
在tableviewcontroller中实现此方法,并在此方法中执行以下操作
如果已在viewcontroller中添加tableview,请执行以下操作-
1) 在.h文件中添加代理@interface TestTableViewController:UIViewController
2) 在(void)viewDidLoad()中的.m文件中添加
self.tableView.delegate=self;
self.tableView.dataSource=self代码>
如果用户单击1-3个单元格,则调用[自执行带有标识符的GUE:SEGUE_SHOWDETAILS发送者:self]代码>在DidSelectRowatineXpath方法中重定向到新页面
对于4-5个单元格,请在DidSelectRowatineXpath方法中更改单元格背景颜色。在声明您的单元格ForRowatineXpath
时,请确保将自定义单元格添加为:
YourCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果不需要自定义单元格,则将其保留为UITableViewCell
使用didSelectCellAtIndexPath
方法执行以下操作:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *segueIdentifier = [[NSString alloc]init];
switch (indexPath.row) {
case 0:
segueIdentifier = @"segue1";
break;
case 1:
segueIdentifier = @"segue2";
break;
case 2:
segueIdentifier = @"segue3";
break;
if (indexPath.row != 3 && indexPath.row !=4) {
[self performSegueWithIdentifier:segueIdentifier sender:self];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
你的问题不清楚。请详细解释您的问题、预期结果和要求的结果。