Iphone uitableviewcell中有多个按钮
我必须创建一个包含多个按钮的单元格。在这里,tableview是可扩展和折叠的,节数和节中的行数是动态的 我希望以这种方式完成这项任务 也就是说,在每一行中,我只需要4个任务,剩下的任务将显示在下一行。但我的问题是,如果我只有13个任务,而它包含4行,在第一、第二和第三行中它包含4个任务,在最后一行中它只包含1个任务,但我无法确定它的文本也不会根据任务而改变 这是我的密码Iphone uitableviewcell中有多个按钮,iphone,uitableview,ios6,uibutton,Iphone,Uitableview,Ios6,Uibutton,我必须创建一个包含多个按钮的单元格。在这里,tableview是可扩展和折叠的,节数和节中的行数是动态的 我希望以这种方式完成这项任务 也就是说,在每一行中,我只需要4个任务,剩下的任务将显示在下一行。但我的问题是,如果我只有13个任务,而它包含4行,在第一、第二和第三行中它包含4个任务,在最后一行中它只包含1个任务,但我无法确定它的文本也不会根据任务而改变 这是我的密码 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsIn
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([self tableView:tableView canCollapseSection:section])
{
if ([expandedSections containsIndex:section])
{
objePro = [appDelegate.array_proj objectAtIndex:section];
rowcount = [objePro.arr_task count] + 1;
NSLog(@"rowcount %d",rowcount);
if (rowcount < 4)
return 2;
else
{
if (rowcount % 4)
{
NSLog(@"odd: %d",rowcount/4 + 2);
return rowcount/4 + 2;
}
else
{
NSLog(@"even: %d",rowcount/4);
return rowcount/4;
}
}
}
}
return 1;
}
- (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] ;
}
cell.backgroundColor = [UIColor clearColor];
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
if (!indexPath.row)
{
cell.textLabel.textColor = [UIColor whiteColor];
UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectZero];
cell.backgroundView = backgroundView;
backgroundView.image = [UIImage imageNamed:@"prjctcell_bg.png"];
objePro = [appDelegate.array_proj objectAtIndex:indexPath.section];
cell.textLabel.text = objePro.projctname;
if ([expandedSections containsIndex:indexPath.section])
cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor blackColor] type:DTCustomColoredAccessoryTypeUp];
else
cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor blackColor] type:DTCustomColoredAccessoryTypeDown];
}
else
{
// all other rows
cell.accessoryView = nil;
j=4;
for (k = 0; k<4; k++)
{
NSLog(@"k %d",k);
btnexpand = [[UIButton alloc] init];
btnexpand = [UIButton buttonWithType:UIButtonTypeCustom];
btnexpand.frame = CGRectMake(j, 5, 80, 40);
btnexpand.backgroundColor = [UIColor clearColor];
[btnexpand setTitleColor:[UIColor colorWithRed:53.0/255 green:53.0/255 blue:53.0/255 alpha:1.0] forState:UIControlStateNormal];
btnexpand.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[btnexpand setTitle:[NSString stringWithFormat:@"Step %d",[[[[appDelegate.array_proj objectAtIndex:indexPath.section] arr_task] objectAtIndex:indexPath.row - 1] taskid]] forState:UIControlStateNormal];
NSLog(@"btn title: %@",btnexpand.titleLabel.text);
[btnexpand setBackgroundImage:[UIImage imageNamed:@"greenarrow.png"] forState:UIControlStateNormal];
[cell.contentView addSubview:btnexpand];
j= j+65;
}
}
}
return cell;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
if([自身表格视图:表格视图可合并部分:节])
{
if([扩展节包含索引:节])
{
objePro=[appDelegate.array_proj objectAtIndex:section];
行计数=[objePro.arr_任务计数]+1;
NSLog(@“行计数%d”,行计数);
如果(行数<4)
返回2;
其他的
{
如果(行计数%4)
{
NSLog(@“奇数:%d”,行数/4+2);
返回行计数/4+2;
}
其他的
{
NSLog(@“偶数:%d”,行数/4);
返回行计数/4;
}
}
}
}
返回1;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier];
}
cell.backgroundColor=[UIColor clearColor];
if([self tableView:tableView canCollapseSection:indexPath.section])
{
如果(!indexPath.row)
{
cell.textLabel.textColor=[UIColor whiteColor];
UIImageView*backgroundView=[[UIImageView alloc]initWithFrame:CGRectZero];
cell.backgroundView=背景视图;
backgroundView.image=[UIImage ImageName:@“prjctcell_bg.png”];
objePro=[appDelegate.array_proj objectAtIndex:indexath.section];
cell.textlab.text=objePro.projctname;
if([expandedSections包含索引:indexath.section])
cell.accessoryView=[DTCustomColoredAccessoryWithColor:[UIColor blackColor]类型:DTCustomColoredAccessoryTypeUp];
其他的
cell.accessoryView=[DTCustomColoredAccessoryWithColor:[UIColor blackColor]类型:DTCustomColoredAccessoryTypeDown];
}
其他的
{
//所有其他行
cell.accessoryView=nil;
j=4;
对于(k=0;kInnumberofrowsin部分
rowcount = [objePro.arr_task count]; // Keep original count
if (rowcount % 4) // This means its not exact multiple of four
return rowcount/4 + 2;
else
return rowcount + 1;
在cellForRowAtIndexPath中
if(indexpath.row == 0){
Your code for header line
}
else{
objePro = [appDelegate.array_proj objectAtIndex:section];
int rowcount = [objePro.arr_task count];
if(rowcount < 4){
for(int i = 0; i < 4; i++){
NSLog (@"%d", i+1);
}
}
else{
int iRow = rowcount / 4;
if (rowcount % 4){
for(int i = 0; i < 4; i++)
NSLog(@"Current Step %d", indexpath.row-1 + i);
}
else{
for(int i = 0; i < rowcount % 4; i++)
NSLog(@"Current Step %d", indexpath.row-1 + i);
}
}
}
if(indexpath.row==0){
标题行的代码
}
否则{
objePro=[appDelegate.array_proj objectAtIndex:section];
int rowcount=[objePro.arr_task count];
如果(行数<4){
对于(int i=0;i<4;i++){
NSLog(@“%d”,i+1);
}
}
否则{
int iRow=行数/4;
如果(行计数%4){
对于(int i=0;i<4;i++)
NSLog(@“当前步骤%d”,indexath.row-1+i);
}
否则{
对于(int i=0;i
这都是骗局,你需要付出一些努力。希望我已经给你指明了方向。@Manohar,我不想创建自定义单元格。没有自定义单元格会发生这种情况吗。那就是我:(我打印错了)