UIButton和UILabel不从View外的UIButton更新

时间:2016-05-13 15:16:07

标签: ios objective-c uibutton

我有一个view,其中UITabelView有可移动的行,用于调整我view内不同ViewController的按钮。 移动行时,view中的图标应更新。见下文(注意[self refreshicons]):

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
     NSInteger sourceRow = sourceIndexPath.row;
     NSInteger destRow = destinationIndexPath.row;
     id object = [shortcutApps objectAtIndex:sourceRow];

     [shortcutApps removeObjectAtIndex:sourceRow];
     [shortcutApps insertObject:object atIndex:destRow];
     [tableView reloadData];
     [self refreshIcons];

     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
     [userDefaults setObject:shortcutApps forKey:@"ShortcutArray"];
}

这是[self refreshicons]

-(void)refreshIcons{
 icon1 = [shortcutApps objectAtIndex:0];
 NSLog(@"%@",icon1);
 [extraIcon1 setImage:[UIImage imageNamed:[[icon1 lowercaseString] stringByReplacingOccurrencesOfString:@" " withString:@""]] forState:UIControlStateNormal];
 extraIconLabel1.text = icon1;
 NSLog(@"%@",extraIconLabel1);
}

NSLogs打印正确的字符串,但UILabel和UIButton图像不会更新。当创建一个按钮,在同一个[self refreshicons]中存在与view相同的代码时,代码会按照需要运行。但是当移动行或在view外按下按钮时,标签和按钮不会更新。 想法?

1 个答案:

答案 0 :(得分:0)

似乎tableview:cellForRowAtIndexPath:方法中发生的任何事情都会覆盖您的图标。

我猜的refreshIcons中的引用是指您保留的以便快速更新值的引用,但它们可能会通过reloadData周期。