티스토리 뷰


IB에서 일반 View를 생성하여 UITextField를 추가하여 정보를 입력 받는 방식만 써오다가

다른 어플들이 많이 사용하고 있는 TableViewCell 에서 직접 입력받는 방식을 구현하였다. 
아래에서 구현한 내용중에 입력을 받는 TextField와 관련된 키보드 처리와 관련된 메소드는 아직 미구현...

//

//  CWTextInputTableViewCell.h

//  RoadDesigner

//

//  Created by Changwook Jeong on 11. 3. 4..

//  Copyright 2011 GNR Technology Inc. All rights reserved.

//


#import <UIKit/UIKit.h>



@interface CWTextInputTableViewCell : UITableViewCell {

UILabel *_mainLabel;

UITextField *_inputField;

}


@property (nonatomic, retain) UILabel *mainLabel;

@property (nonatomic, retain) UITextField *inputField;


@end



//

//  CWTextInputTableViewCell.m

//  RoadDesigner

//

//  Created by Changwook Jeong on 11. 3. 4..

//  Copyright 2011 GNR Technology Inc. All rights reserved.

//


#import "CWTextInputTableViewCell.h"



@implementation CWTextInputTableViewCell

@synthesize mainLabel = _mainLabel;

@synthesize inputField = _inputField;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {

        // Initialization code.

_inputField = [[UITextField alloc] initWithFrame:CGRectMake(10.0, 0.0, self.bounds.size.width-30.0, self.bounds.size.height)];

_inputField.font = [UIFont systemFontOfSize:17.0];

_inputField.textAlignment = UITextAlignmentLeft;

_inputField.textColor = [UIColor blackColor];

_inputField.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;

_inputField.leftViewMode = UITextFieldViewModeAlways;

_inputField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

_inputField.clearButtonMode = UITextFieldViewModeWhileEditing;

[self.contentView addSubview:_inputField];

_mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 90.0, self.bounds.size.height)];

_mainLabel.font = [UIFont systemFontOfSize:17.0];

_mainLabel.textAlignment = UITextAlignmentLeft;

_mainLabel.adjustsFontSizeToFitWidth = YES;

_mainLabel.textColor = [UIColor blackColor];

//_mainLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;

[_inputField setLeftView:_mainLabel];

self.selectionStyle = UITableViewCellSelectionStyleNone;

    }

    return self;

}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    

    [super setSelected:selected animated:animated];

    

    // Configure the view for the selected state.

}



- (void)dealloc {

[_mainLabel release];

[_inputField release];

    [super dealloc];

}



@end







* 사용할때는 아래와 같이 사용하면 된다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    

static NSString *cellIdentifier = @"Cell";

CWTextInputTableViewCell *cell = 

(CWTextInputTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell == nil) {

cell = [[[CWTextInputTableViewCell alloc]

 initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];


}

cell.mainLabel.text = @"mainLabel";

return cell;

}




공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함