我是 iOS 应用程序开发的新手,所以需要一点支持!! 我在 objectiveC 中使用了一个 TableView 来制作一个下拉列表以显示已成功制作的国家/地区名称,但现在我希望将同一个 tableView 用于不同的州列表,因为我有两个NSMutable 数组一个用于“countryList”,另一个用于“stateList” 我可以使用相同的 tableView 但显示 stateList 数据吗?
NSMutableArray *countryArray;
NSMutableArray *stateArray;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return countryArray.count ;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 25;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
static NSString *idenfier = @"countryList";
cell = [tableView dequeueReusableCellWithIdentifier:idenfier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = [countryArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.registerCountry.text = [[[tableView cellForRowAtIndexPath:indexPath] textLabel] text];
// self.countryView.hidden = YES;
self.countryView.frame = CGRectMake(self.countryView.frame.origin.x, self.countryView.frame.origin.y, self.countryView.frame.size.width, 0);
if([_registerCountry.text isEqual:@""]){
[_dropDownState setEnabled:NO];
}
else{
[_dropDownState setEnabled:YES];
}
}
- (IBAction)dropDownCountry:(id)sender {
self.countryView.hidden = NO;
if (self.countryView.frame.size.height != 0) {
[UIView animateWithDuration:0.3 animations:^{
self.countryView.frame = CGRectMake(self.countryView.frame.origin.x, self.countryView.frame.origin.y, self.countryView.frame.size.width, 0);
} completion:^(BOOL finished) {
// self.dropDownImageView.highlighted = NO;
}];
}
else {
[UIView animateWithDuration:0.3 animations:^{
self.countryView.frame = CGRectMake(10, 404, 302, 100);
} completion:^(BOOL finished) {
// self.dropDownImageView.highlighted = YES;
}];
}
}
- (IBAction)dropDownState:(id)sender {
}
最佳答案
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return stateList.count
//OR
return countryList.count
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Load cell with the array[indexPath.row] you want
}
关于ios - 想要使用相同的 TableView 一次从两个数组填充数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39269342/