我使用Interface Builder添加了工具栏,但我需要在运行时/有条件地添加按钮。我没有收到任何错误,但我的动态按钮未显示在工具栏上。我已经验证了arrayOfModulesScreens加载了我需要的数据。至少这方面是有效的(:))。我需要将按钮添加到UIView中,然后将该视图添加到工具栏中吗?只是想想而已。也许有更好的方法开始?感谢提前提供任何线索以解决问题。
CustomFormController.h
CustomFormController.h
@interface CustomFormController : UIViewController {
UIToolbar *screensBar;
}
CustomFormController.m
EPData *epData = [[EPData alloc] init];
NSArray *screens = [epData loadPlistIntoArray:@"Screens"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"process_module_id == %@", process_modulesID];
NSArray *arrayOfModulesScreens = [screens filteredArrayUsingPredicate:predicate];
for(int i=0; i < [arrayOfModulesScreens count]; i++) {
NSDictionary *dictRow = [arrayOfModulesScreens objectAtIndex:i];
UIButton *button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[button setTitle:[dictRow objectForKey:@"screen_title"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[screensBar addSubview:button];
}