Я хочу создать UITableView в UIAlertController с iOS8.Как установить положение и размер UITableView в UIAlertController с iOS8
Мне нужен эффект, как показано ниже, это оригинальный компонент iOS8, всплывающее окно alertview и внутри UITableView.
Я пытаюсь построить UITableView в UIAlertController, но я не знаю, как установить размер и положение, как на фото.
Есть ли у кого-нибудь знать, как настроить положение и размер UITableView в UIAlertController?
мой код ниже:
@interface ViewController()
@property (nonatomic,strong) UITableView *tableView;
@property(strong,nonatomic) NSMutableArray *titleArray;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.titleArray = [[UIFont familyNames] mutableCopy];
for(int i = 0; i < 100; i++) {
[self.titleArray addObjectsFromArray:[UIFont familyNames]];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self showUIAlertTable];
});
}
-(void) showUIAlertTable
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
message:@"select network\n\n\n"
preferredStyle:UIAlertControllerStyleAlert];
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[alert.view addSubview:self.tableView];
[self presentViewController:alert animated:NO completion:nil];
}
#pragma mark - UITableViewDataSource Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return [self.titleArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
cell.textLabel.text = [self.titleArray objectAtIndex:indexPath.row];
[cell setNeedsUpdateConstraints];
return cell;
}
Код эффекта запустить эффект ниже:
Это не мой ожидать эффекта.
Кто-нибудь может научить меня, как исправить?
спасибо.
(я должен был использовать autolayout)
http://stackoverflow.com/questions/19216477/how -to-add-a-uitableview-in-uialertview-in-ios-7 –
@ T_77, это просто для iOS7 .. – dickfala