gpt4 book ai didi

ios - 如何显示界面生成器中定义的自定义单元格?

转载 作者:行者123 更新时间:2023-11-29 04:29:19 24 4
gpt4 key购买 nike

我正在尝试嵌入自定义设计的 TableView 单元格(在界面生成器中)。对于初学者,我尝试在其自己的部分中添加一些文本字段。我能够显示定制设计的表格 View ,但是我做了一些不正确的事情,因为它看起来一团糟。也不太清楚如何添加其他部分。有人可以引导我走向正确的方向吗?我尝试了以下操作:http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW20

但是有点迷失了。

它是这样的:

enter image description here

这是我在界面生成器中的设置:

enter image description here

这是我的代码:

头文件:

#import <UIKit/UIKit.h>

@interface SearchTableViewController : UITableViewController
{

}
@property (nonatomic, retain) IBOutlet UITableViewCell *priceRanceCell;
@end

实现:

#import "SearchTableViewController.h"


@interface SearchTableViewController ()

@end

@implementation SearchTableViewController
@synthesize priceRanceCell=_priceRanceCell;




- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Some Search", @"Some Search");
self.tabBarItem.image = [UIImage imageNamed:@"search"];
}
return self;
}




- (void)viewDidLoad
{
[super viewDidLoad];

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SearchViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...
NSInteger section = [indexPath section];


switch (section) {
case 0: // First cell in section 1


return self.priceRanceCell;


break;
default:
// Do something else here if a cell other than 1,2,3 or 4 is requested

return cell;

break;
}








return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}

@end

最佳答案

您需要实现heightForRowAtIndexPath:。另请注意,当您使用 dequeueReusableCellWithIdentifier: 时,结果可能为零,在这种情况下您需要创建一个单元。你应该修改你的逻辑,这样你就不会尝试它的第 0 部分。

关于ios - 如何显示界面生成器中定义的自定义单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11925613/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com