我在TableView中有一个包含对象的列表。带有对象的列表正在从服务器上的外部.plist加载。现在我想得到它,当TableView中的单元格被轻敲时它们变成另一种颜色(绿色),当完成点击单元格时,您可以按下一个按钮,将点击的单元格(对象的名称)发送到电子邮件地址或服务器,因此应用程序的所有者可以看到选择了哪些对象。
任何人都可以帮助我(或指出我正确的方向)如何做到这一点?
我的TableView代码:(查看controller.m)
#import "ViewController.h"
#import "Stuff.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Stuff *s = [[Stuff alloc] init];
[s getStuff];
self.items = [[NSMutableArray alloc] initWithArray:s.stuff];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.items count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
NSString *id = @"plistdata";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:id forIndexPath:indexPath];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:id];
}
cell.textLabel.text = self.items[indexPath.row];
return cell;
}
@end
如果需要更多代码,请告诉我
提前致谢
答案 0 :(得分:0)
我建议您在苹果网站上阅读UITableView。
但是,如果你在点击/选择一个单元格时想要触发某些东西,那么也许你应该考虑
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
跟踪已点击的单元格。我还要确保您在表格视图中启用了多项选择。
也许请阅读此http://www.cocoawithlove.com/2009/01/multiple-row-selection-and-editing-in.html
希望有所帮助
答案 1 :(得分:0)
创建一个与之前加载的电子邮件列表大小相同的数组,该列表与表视图中的行数相同,并使用错误的布尔对象填充此数组
并在CellForRowAtIndexPath中使用indexPath.row从该数组中获取布尔对象并检查其值True是绿色,False是默认颜色
然后将布尔值设置为true,与didSelectRowAtIndexPath中的选定单元格具有相同的索引,然后在UITableView上调用loadData方法刷新界面