根据UIPickerView更新UITableView单元格

时间:2016-04-28 21:59:48

标签: ios objective-c uitableview uipickerview

我有UIPickerView

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView     
{     
 return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{
 return seasons.count;
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{
 if ([season selectedRowInComponent:0] == 6) {
    matches = [[NSMutableArray alloc] initWithCapacity: 20];
    [matches insertObject:[NSMutableArray arrayWithObjects:@"aaa", @"bbb", @"1-0", @"15-03-2010", nil] atIndex:0];
 } else if
 .
 .
 .
}

然后我有UITableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return matches.count;
}

- (CustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{     
 static NSString *simpleTableIdentifier = @"customCell";

 CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

 if (cell == nil) {
    cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
 }
 cell.team1.text = matches[indexPath.row][0];
 cell.team2.text = matches[indexPath.row][1];
 cell.score.text = matches[indexPath.row][2];

 return cell;
}

现在,UITableView填充了我在matches初始化的viewDidLoad数组中的对象。如何根据UIPickerView

的选定行更新单元格内容

1 个答案:

答案 0 :(得分:2)

更新void Main::readFile() { while (v.size() != 0) { string name; name = v.at(v.size()-1); v.pop_back(); std::ofstream out(name + ".txt"); ifstream file; file.open("letter.txt"); string word; string comma; char x; word.clear(); while (!file.eof()) { x = file.get(); while (x != ' ' && x != std::ifstream::traits_type::eof()) { if (word == "@name@") { word = name; } if (word == "@festival@") { word = "THISISATEST!!!!!!!!!!!!!!"; } word = word + x; x = file.get(); } out << word + " "; word.clear(); } } 数组后,只需致电<head> <style> input{ border: 5px solid red;} </style> </head> <div class="in"> <input class="input" type="text" name="text" method="post"> </div>

[self.tableView reloadData];

这假设matches既是表视图数据源/委托又是选择器视图数据源/委托