【发布时间】:2013-12-17 21:46:12
【问题描述】:
如何从 tableviewcells 中的分段控件中获取值(选定状态)? 当我按下“获取状态”按钮时,它应该返回每个分段控件的值。我尝试了不同的方法,但我找不到一种有效的方法:(
到目前为止我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
tableData = [[NSMutableArray alloc] initWithCapacity:0];
tableData = [NSArray arrayWithObjects:@"First", @"Second", @"Third", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"StateCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"StateCell"];
}
//Config cell..
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
NSArray *itemArray = [NSArray arrayWithObjects: @"1", @"2", @"3", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(110, 7, 100, 28);
[cell.contentView addSubview:segmentedControl];
return cell;
[[self tableView] reloadData];
}
- (IBAction)getStates:(id)sender {
// Ruturn the current selected statement, for the individual cell's segmentedcontrol..
// Ex. First = SelectedState 1, Second = SelectedState 0 & Third = SelectedState 2..
}
所以我真正想要的是;是“获取状态”按钮操作必须执行的操作..
感谢您的宝贵时间!
【问题讨论】:
-
您自己尝试过吗?还是你只是要代码?
-
嗨。我一直在尝试各种方法..所以代码会非常好!我只有 15 岁,对 IOS 开发还很陌生;)
-
请将您尝试过的代码添加到您的问题中,并详细说明您遇到的具体部分以及出了什么问题。
-
我发现的最后一个方法充满了错误和过时的代码:(如果你能帮助我继续我的项目,这将对我有很大帮助!:) 谢谢
-
您需要在问题中添加相关代码,否则我们无法帮助您。我们需要先了解您做错了什么,然后才能告诉您要解决的问题。
标签: ios xcode uitableview ios7 uisegmentedcontrol