【发布时间】:2016-05-04 11:38:04
【问题描述】:
在我的应用程序中,我想显示一个基于按钮标签的表格视图(自定义单元格),当我点击我的第一个按钮时,它显示空表格视图,点击第二个按钮它显示第一个按钮数据。 这是我到目前为止的代码,我试过了, 我在 ViewDidLoad 方法中调用我的 IBAction 按钮,
- (void)viewDidLoad
{
value1=0;
[self details:nil];
}
这是我的 IBAction 方法,
-(IBAction)details:(id)sender
{
value1 = 0;
detaiLine.hidden = NO;
rewardLine.hidden = YES;
[testTableView reloadData];
}
这是我的 tableViewDataSource 方法,
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return responseArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (value1 == 0)
{
return 104;
}
if(value1 == 1)
{
return 180;
}
return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (value1 == 0)
{
static NSString *cellId = @"Cell1";
ContestDetailCell1 * cell = (ContestDetailCell1 *)[contestTableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
NSArray *myNib;
myNib = [[NSBundle mainBundle]loadNibNamed:@"ContestDetailCell1" owner:self options:nil];
cell = [myNib lastObject];
}
}
if(value1 == 1)
{
static NSString *cellIdentifier = @"Cell2";
ContestDetailCell2 *cell = (ContestDetailCell2 *)[contestTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
NSArray *myNib;
myNib = [[NSBundle mainBundle]loadNibNamed:@"ContestDetailCell2" owner:self options:nil];
cell =[myNib objectAtIndex:0];
}
}
我的代码有什么问题。
【问题讨论】:
-
In viewDidLoad: 你已经发布了 value=0;,是代码中的错字还是类似的错误,因为当你的表加载时 value1 根本没有设置第一次。另外,我猜在 reloadData 中不会调用 heightForRowAtIndexPath。请检查。
-
@user3300864 我会检查并通知你
-
@user3300864 heightForRowAtIndexPath 正在调用。
-
你的笔尖可能没有初始化。你在注册你的 xib 吗?
标签: objective-c uitableview uibutton custom-cell