将复选框添加到 UITableView 中的部分之一 [英] adding check box to one of sections in UITableView

查看:32
本文介绍了将复选框添加到 UITableView 中的部分之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以编程方式创建了一个表视图控制器,其中包含不同的部分我想在第三部分中添加带有复选标记框的 3 行(我使用了故事板!)请你给我一些提示,我该怎么做..

I create a table view controller programmatically that contains different sections I want to add 3 rows with check mark box in my third sections (I used storyboard!) would you please give me some hint that how can I do that ..

我的问题是如何在左侧为我的第三部分设置复选框

这是图片:而不是请设置您的代码:在缺席代码部分有 3 行带有复选标记框

here is the picture:instead of Please set your code: having 3 rows with check mark box in Absence Code sections

这是我在故事板中的观点:

Here is my view in storyboard:

代码如下:

- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *keys = [[NSMutableArray alloc] init];
NSMutableDictionary *contents = [[NSMutableDictionary alloc] init];


NSString *staKey = @"Start";
NSString *endKey = @"End";
NSString *absKey= @"Absence";

[contents setObject:[NSArray arrayWithObjects:@"Time: 08:00 Date: Fri,3 Aug, 2012", nil] forKey:staKey];
[contents setObject:[NSArray arrayWithObjects:@"Time: 17:57 Date: Fri,3 Aug, 2012", nil] forKey:endKey];
[contents setObject:[NSArray arrayWithObjects:@"Please set your code", nil] forKey:absKey];

[keys addObject:staKey];
[keys addObject:endKey];
[keys addObject:absKey];


[self setSectionKeys:keys];
[self setSectionContents:contents];
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *key = [[self sectionKeys] objectAtIndex:[indexPath section]];
NSArray *contents = [[self sectionContents] objectForKey:key];
NSString *contentForThisRow = [contents objectAtIndex:[indexPath row]];

static NSString *CellIdentifier = @"CellIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
reuseIdentifier:CellIdentifier];
}

[[cell textLabel] setText:contentForThisRow];
return cell;

 }


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSMutableArray *weekArray = [[ NSMutableArray alloc] initWithObjects: @"Start Time", @"End Time",@"Absence Code", 
 nil];

return [weekArray objectAtIndex:section];
}


- (UITableViewCellAccessoryType)tableView:(UITableView *)tv accessoryTypeForRowWithIndexPath:(NSIndexPath  
*)indexPath {
return UITableViewCellAccessoryDisclosureIndicator;
}

提前致谢!

推荐答案

检查 选择 UITableView 的多行 链接获得帮助.

Check Selecting multiple rows of a UITableView link get helped.

这样做:在下面的方法中更改代码:

Do this: change code in below method:

- (UITableViewCellAccessoryType)tableView:(UITableView *)tv accessoryTypeForRowWithIndexPath:(NSIndexPath  *)indexPath {
 if(indexPath.section ==2)
 {
  return UITableViewCellAccessoryCheckMark;
 }
 else
 {
  return UITableViewCellAccessoryDisclosureIndicator;
 }
}

这篇关于将复选框添加到 UITableView 中的部分之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆