I try to add tableView and TextField inside the ModalView. I do so. I create new View Controller and give for it
#import <UIKit/UIKit.h>
@protocol UYLModalViewControllerDelegate
-(void) buttonDonePassed :(NSArray *) variables;
@end
@interface UYLModalViewController : UIViewController <UITableViewDelegate>
{
id<UYLModalViewControllerDelegate> delegate;
IBOutlet UITableView *tblView;
IBOutlet UITextField *textField;
NSMutableArray *cellsArray;
//UITextField *textField;
}
@property (nonatomic, assign) id<UYLModalViewControllerDelegate> delegate;
@property (nonatomic, retain) IBOutlet UITableView *tblView;
@property (retain, nonatomic) IBOutlet UITextField *textField;
@end
And IN .m File I create functions
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [cellsArray 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] autorelease];
}
cell.textLabel.text = [cellsArray objectAtIndex:indexPath.row];
// Configure the cell.
return cell;
}
and ViewDidiLoad
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(buttonPassed:)];
//UITableView *tableView = [[UITableView alloc] init];
//[self]
cellsArray = [[NSMutableArray alloc] initWithObjects:@"one",@"two",@"three", nil];
[tblView reloadData];
}
But my program don’t go to the TableViewDelegate methods (such as cellforrowAtIndexPath)
You need to set your
UYLModalViewControlleras thetableView‘sdelegateanddatasource.It looks like you are using
Interface Builderso you need to:control + clickon the tableView and drag it across to theFile's Ownerdatasourcefrom the HUD menu.delegateNote
Your controller should also conform to
UITableViewDatasourcegiving you:1.
2.
If you prefer you can do this in code in
viewDidLoador any place where you create thetableViewif you do it programatically.