问题
I am using story board. I want to add a subview when a element is selected on table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arr 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];
}
NSString *cellvalue = [arr objectAtIndex:indexPath.row];
cell.textLabel.text=cellvalue;
cell.imageView.image=[UIImage imageNamed:@"1.png"];
return cell;
}
回答1:
Storyboards are useful to show your app flow.Hence there is no point in adding a view without showing the flow in story board.
storyboard segues(connection between on view to another) are three types,push,modal and custom. If you don't want to do a push or present as a modal, you can create your own custom segue by over riding the perform method of UIStoryboardSegue.
- (void)perform
{
// Add your own code here.
[[self sourceViewController] addChildViewController:[self destinationViewController]];
}
Developer reference for custom segues.
回答2:
If you want ti make it straight from StoryBoard you need to Ctrl-drag from the table view cell (prototype cell) to the destination view.
来源:https://stackoverflow.com/questions/18075389/how-to-add-subview-in-table-view-using-story-board