【发布时间】:2016-09-02 18:12:47
【问题描述】:
我是 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 {
}
【问题讨论】:
-
请在此处复制粘贴您的代码以提供更多详细信息
-
绝对有可能。发布一些代码作为亚历山大笔记,或发布您的数据源。
-
你想如何显示国家和州列表?意味着它会改变哪个动作?你能提供那个图片..
标签: ios objective-c