我已经使用 Interface Builder 添加了工具栏,但我需要在运行时/有条件地添加按钮。我没有收到任何错误,但我的动态按钮没有出现在工具栏上。我已经验证 arrayOfModulesScreens 加载了我需要的数据。至少那有效(:))。我是否需要将按钮添加到 UIView,然后将该视图添加到工具栏?只是大声思考。也许有更好的方法开始?提前感谢您提供解决问题的任何线索。
CustomFormController.h
@interface CustomFormController : UIViewController {
UIToolbar *screensBar;
}
自定义表单控制器.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];
}