AlertController with Table View & with Label inside it...
StoryBoard...
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (IBAction)alertWithLabelBtnTapped:(id)sender;
- (IBAction)alertWithTVBtnTapped:(id)sender;
@end
#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)alertWithLabelBtnTapped:(id)sender {
UIViewController *controller = [[UIViewController alloc]init];
CGRect rect = CGRectMake(0, 0, 180, 50);
[controller setPreferredContentSize:rect.size];
UILabel *alertLbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 180, 40)];
alertLbl.backgroundColor = [UIColor orangeColor];
alertLbl.text = @" I am Alert Label";
alertLbl.textColor = [UIColor greenColor];
[controller.view addSubview:alertLbl];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
[alertController setValue:controller forKey:@"contentViewController"];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
}];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
- (IBAction)alertWithTVBtnTapped:(id)sender {
UIViewController *controller = [[UIViewController alloc]init];
UITableView *alertTableView;
CGRect rect = CGRectMake(0, 0, 280, 250);
[controller setPreferredContentSize:rect.size];
alertTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 280, 250)];
alertTableView.delegate = self;
alertTableView.dataSource = self;
alertTableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
[alertTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[alertTableView setTag:1];
[controller.view addSubview:alertTableView];
[controller.view bringSubviewToFront:alertTableView];
[controller.view setUserInteractionEnabled:YES];
[alertTableView setUserInteractionEnabled:YES];
[alertTableView setAllowsSelection:YES];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
[alertController setValue:controller forKey:@"contentViewController"];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
}];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 8;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"CellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] ;
}
cell.textLabel.text = @"Hellooo";
return cell;
}
@end
Results:
No comments:
Post a Comment