开发者

A UITextField in a UITableViewCell - UIButton

I have successfully implemented a UITextField in a UITableViewCell. Just like this:

A UITextField in a UITableViewCell - UIButton

.

I did the above using code in: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath.

Now I would like to place a UIButton underneath these 2 UITableViewCells. Can I code a UIButton in? How can I do this and where?

Thanks.

New Button Position

开发者_如何学Go

A UITextField in a UITableViewCell - UIButton

Interface Builder

A UITextField in a UITableViewCell - UIButton


You can do it in the same method also,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  if(indexPath.row==2)
  {
   //Create a UIButton
   //Assign target
   //Add the button as a subview to cell.contentView
  }
else
  {
   //Add the textFields
  }
}

To create a button code as,

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton.frame = CGRectMake(20, 20, 200, 44); // position in the cell and set the size of the button
    [myButton setTitle:@"Login" forState:UIControlStateNormal];
    // add targets and actions
    [myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    // add to a view
    [cell.contentView addSubview:myButton];


You can use this to add a button to tableView's footer View

tableView.tableFooterView = [[[UIButton alloc] initWith:] autorelease];

or you can add a button to section footer view. using the method

viewForFooterInSection


You would probably have to make a UIViewController the controller of the table view. That way you can add a UIButton onto the view as well as the table view.

Just make the UIViewController a UITableViewDelegate and UITableViewDataSource, create a UITableView in the UIViewController and copy the code from the UITableViewController into the UIVIewController. Then add a UIButton below it.

This is what I have done in the past. I only use UITableViewController if I want just a table view dislayed for things like lists.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜