0

カスタムデザインのTableViewセルを(Interface Builderに)埋め込もうとしています。手始めに、私は独自のセクションにいくつかのテキストフィールドを追加しようとしています。カスタムデザインのテーブルビューを表示することはできますが、すべてが台無しに見えるため、間違ったことをしています。また、セクションを追加する方法についても明確ではありません。誰かが私を正しい方向に導くことができますか?次のことを試しました:http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW20

しかし、少し迷子になりました。

これがどのように見えるかです:

ここに画像の説明を入力してください

これは、InterfaceBuilderでの私の設定です。

ここに画像の説明を入力してください

これは私のコードです:

ヘッダーファイル:

#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
4

2 に答える 2

1

を実装する必要がありますheightForRowAtIndexPath:dequeueReusableCellWithIdentifier:また、の場合、結果はnilになる可能性があることに注意してください。この場合、セルを作成する必要があります。セクション0の場合でも試行しないように、ロジックを変更する必要があります。

于 2012-08-12T21:37:30.340 に答える
0

Interface Builderで、作成したカスタムセルをクリックし、高さを記憶します。次に、使用するテーブルビューをクリックし、メモリから行の高さを入力します。

于 2013-09-10T14:05:58.270 に答える