我正在uipicker
內uitableview's prototype cell
我在那裏創建一個uilabel
。現在我在標籤上添加選擇器視圖行選擇的值,但是我的問題是,當我從選擇器視圖選擇行時,所有標籤都會更新。如何在uilabel上添加uipickerview選定的行值?
值應在uilabel
的選定行上更新。這是我的代碼和屏幕截圖。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [myData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
UILabel *lable = (UILabel*)[cell viewWithTag:111];
lable.tag = indexPath.row;
lable.text = value;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
_nameLabel.text =nil;
[self.mytableview reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:NO];
[self bringUpPickerViewWithRow:indexPath];
}
- (void)bringUpPickerViewWithRow:(NSIndexPath*)indexPath
{
UITableViewCell *currentCellSelected = [self.mytableview cellForRowAtIndexPath:indexPath];
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^
{
self.pickerView.hidden = NO;
self.pickerView.center = (CGPoint) { currentCellSelected.frame.size.width/2, self.mytableview.frame.origin.y + currentCellSelected.frame.size.height*4};
self.mytableview.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.mytableview setNeedsDisplay];
}
completion:nil];
}
- (void)hidePickerView
{
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^
{
self.pickerView.center = (CGPoint){160, 800};
}
completion:^(BOOL finished)
{
self.pickerView.hidden = YES;
[self.mytableview reloadData];
}];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return _countingarray.count;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component
{
[self.mytableview reloadData];
[self hidePickerView];
NSLog(@"row selected:%ld", (long)row);
NSString *resultString = _countingarray[row];
value = resultString;
}
- (NSString*) pickerView:(UIPickerView *)pickerView titleForRow: (NSInteger)row forComponent:(NSInteger)component
{
//return [NSString stringWithFormat:@"%d", row+1];
return _countingarray[row];
}
- (IBAction)editbuttonclicked:(id)sender {
if([self.mytableview isEditing] == NO){
//[self.mytableview settitle:@"Done"];
//set the table to editing mode
[self.mytableview setEditing:YES animated:YES];
}else
{
//we are currently in editing mode
//change the button text back to Edit
//[self.editbutton setTitle:@"Edit"];
//take the table out of edit mode
[self.mytableview setEditing:NO animated:YES];
}
}
-(void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[myData removeObjectAtIndex:indexPath.row];
[self.mytableview deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
有人幫我PLZ –
你已經有一個'myData'您使用爲了確定在tableView中應該顯示多少行,您應該可以使用該數組中的任何內容來確定每個標籤顯示的文本。在你做完這些之後,你應該需要'value',但是應該只處理該數組中的數據,然後再處理'reloadData'。 – luk2302
價值是如何申報的? –