how To add subview in table view using story board

六眼飞鱼酱① 提交于 2019-12-12 08:59:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!