2014-01-10 1 views
4

제발 저와 함께 있으십시오. iOS 개발을 시작했습니다. 스토리 보드 을 스토리 보드 tableView에 표시하려고합니다. 나는 다음을했다.iOS 7 사용자 정의 셀이 테이블보기에 표시되지 않습니다.

내가

enter image description here

tableViewCell로 새로운 .xib을 만든 I는이에 대한 사용자 정의 클래스를 만들었습니다. .H 파일은 내 TableViewController.m에서 내가 가져온이

#import <UIKit/UIKit.h> 

@interface CustomTableCell : UITableViewCell 

@property (weak, nonatomic) IBOutlet UIImageView *thumbnailImageView; 
@property (weak, nonatomic) IBOutlet UILabel› *titleLabel; 

@end 

처럼 보이는 CustomTableCell.h 내가하지만, 10 행

이 구축 잘 보인다
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 10; 
} 

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

    if(cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomTableCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

    cell.titleLabel.text ="test text"; 


    return cell; 
} 

을 위해 다음을 수행하고 때 프로젝트로드 아무것도 일어난다. 어떤 조언도 훌륭합니다.

cellForRowAtIndexPath 메서드에 중단 점을 배치했지만이 지점에 도달하지 않습니다. 여기 시뮬레이터

enter image description here

+0

를 하나의 항목 만이해야? 테이블 뷰가 나타 납니까? –

+0

그냥 분명히, 나머지 UITableView 데이터 소스/위임 메서드 게시 할 수 있습니까? –

+0

"아무 일도 일어나지 않습니다"는 의미가 없습니다. _무언가가 일어난다. 뭐? – matt

답변

9

당신은 펜촉을로드하는 방법은 정말 구식 오래된이다. 펜촉을 등록하고 dequeueReusableCellWithIdentifier:forIndexPath:을 사용하면 훨씬 더 좋습니다 (iOS 6 이후).

사용자 지정 셀을 가져 오는 네 가지 방법 중 my explanation을 참조하십시오.

+0

내가 잘못하고있는 것이 무엇인지 파악할 수 없습니다. https://github.com/beard3dgeek/customeCellDemo를 잠시 살펴볼 수 있습니까? – c11ada

+0

예, 할 수 있습니다. :) 거기에 매달려. – matt

+0

_MyCustomCell.xib_의 'imageView'및 'titleLabel'콘센트는 이미지보기 및 레이블 객체에 연결되어 있지 않습니다. 그들은 잘못 (잘못) 셀의 내용보기에 연결됩니다. – matt

7

대리인 및 데이터 소스가 jQuery과의 스토리 보드에 설정되어 있는지 확인의 스크린 샷이다. 이렇게하면 각 행에 cellForRowAtIndexPath이 호출됩니다. 동일한 방법을 확인하기 위해 해당 방법에 NSLog 메시지를 넣을 수 있습니다.

또한 스토리 보드를 사용하고 있으므로 UITableView의 프로토 타입 셀을 살펴볼 수 있습니다. 그것들은 같은 일을하는 훨씬 쉬운 방법입니다 - 커스텀 셀을 가지고 UITableView를 생성하십시오.

여기에 스토리 보드의 jQuery과 내에서 프로토 타입의 세포를 사용하는 방법에 괜찮은 튜토리얼입니다 :

http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

+0

이 부분은 정답입니다. 그는 스토리 보드에 델리게이트와 데이터 소스를 연결하지 않았습니다. – matt

1

아주 기본적인 질문,하지만 당신은 표시되어야하는 세포 나타내는있는 tableview의 대리자 메서드를 구현? 위임 방법은 다음과 같다 :

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    //Return number of cells to display here 
    return 1; 
} 
+0

업데이트를 확인하십시오,이 코드를 추가했습니다. – c11ada

12

당신은 당신의 .xib 파일을 등록해야합니다. 당신의 viewDidLoad 방법에서, 다음을 추가 :

[self.tableView registerNib:[UINib nibWithNibName:@"CustomTableCell" bundle:nil] 
    forCellReuseIdentifier:@"CustomTableCell"]; 
+0

이것을 내 테이블 뷰 컨트롤러 viewDidLoad에 추가했으며 내 cellForRowAtIndexPath에도 중단 점을 배치했으나이 시점에 도달하지 못했습니다 !! – c11ada

+1

그것은'nibWithNibName'이어야합니다. – sooper

+0

감사합니다. @sooper, 편집 됨. – Steve

5
- (void) viewDidLoad { 

    [super viewDidLoad]; 

    UINib *cellNib = [UINib nibWithNibName:@"CustomTableCell" bundle:[NSBundle mainBundle]]; 
    [self.tableView registerNib:cellNib forCellReuseIdentifier:@"CustomTableCell"]; 

} 

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

    if(cell == nil) 
    { 
     cell = [[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    cell.titleLabel.text ="test text"; 


    return cell; 
} 
+0

내 코드에 viewDidLoad의'UINib * cellNib = ...'이 없습니다. – byJeevan

0

당신이 시뮬레이터에서보고 무엇 당신의 XIB에 (있는 UITableViewCell 인스턴스)

-1
#import <UIKit/UIKit.h> 
#import "DetailViewController.h" 
#import "NewViewController.h" 
#import "CustomCellVC.h" 

@interface FirstVC : UIViewController 
{ 
    DetailViewController *detailViewController; 
    NewViewController *objNewViewController; 
    CustomCellVC *objCustom; 
    NSMutableData *webData; 
    NSArray *resultArray; 
    //IBOutlet UIButton *objButton; 
} 
@property(strong,nonatomic)IBOutlet DetailViewController *detailViewController; 
@property(strong,nonatomic)IBOutlet UITableView *objTable; 
-(void)loginWS; 
-(IBAction)NewFeatureButtonClk:(id)sender; 
@end 

#import "FirstVC.h" 

@interface FirstVC() 

@end 

@implementation FirstVC 
@synthesize objTable; 
@synthesize detailViewController; 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    objTable.frame = CGRectMake(0, 20, 320, 548); 
    [self loginWS]; 
} 
-(void)loginWS 
{ 
    //Para username password 
    NSURL *url = [NSURL URLWithString:@"http://192.168.0.100/FeatureRequestComponent/FeatureRequestComponentAPI"]; 
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; 
    [req setHTTPMethod:@"POST"]; 
    [req addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 
    // [req addValue:[NSString stringWithFormat:@"%i",postBody.length] forHTTPHeaderField:@"Content-Length"]; 
    [req setTimeoutInterval:60.0 ]; 
    //[req setHTTPBody:postBody]; 
    //[cell setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"CellBg.png"]]]; 

    NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:req delegate:self]; 

    if (connection) 
    { 
     webData = [[NSMutableData alloc]init]; 
    } 

} 
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [webData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [webData appendData:data]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil]; 
    resultArray = [[NSArray alloc]initWithArray:[responseDict valueForKey:@"city"]]; 
    NSLog(@"resultArray: %@",resultArray); 
    [self.objTable reloadData]; 
} 
-(IBAction)NewFeatureButtonClk:(id)sender 
{ 
    objNewViewController=[[NewViewController alloc]initWithNibName:@"NewViewController" bundle:nil]; 
    // Push the view controller. 
    [self.navigationController pushViewController:objNewViewController animated:YES]; 
} 

#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 [resultArray count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    objCustom = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (objCustom == nil) { 
     objCustom = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 


    //objCustom.persnName.text=[[resultArray objectAtIndex:indexPath.row]valueForKey:@"Name"]; 
    //objCustom.persnAge.text=[[resultArray objectAtIndex:indexPath.row]valueForKey:@"Age"]; 


    // Configure the cell... 
    objCustom.textLabel.text = [[resultArray objectAtIndex:indexPath.row] valueForKey:@"FeatureTitle"]; 
    objCustom.detailTextLabel.text = [[resultArray objectAtIndex:indexPath.row] valueForKey:@"Description"]; 


    return objCustom; 
} 

#pragma mark - Table view delegate 

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath: 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Navigation logic may go here, for example: 
    // Create the next view controller. 
    detailViewController = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil]; 
    detailViewController.objData=[resultArray objectAtIndex:indexPath.row]; 
    // Pass the selected object to the new view controller. 

    // Push the view controller. 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
#import <UIKit/UIKit.h> 
#import "DetailData.h" 

@interface DetailViewController : UIViewController 
{ 
    DetailData *objData; 
} 
@property(strong,nonatomic)IBOutlet UITextField *usecaseTF; 
@property(strong,nonatomic)IBOutlet UITextView *featureTF; 
@property(strong,nonatomic)IBOutlet UILabel *priority; 
@property(strong,nonatomic)IBOutlet UIButton *voteBtn; 
@property(strong,nonatomic)IBOutlet DetailData *objData; 
-(IBAction)voteBtnClk:(id)sender; 
@end 
#import "DetailViewController.h" 

@interface DetailViewController() 

@end 

@implementation DetailViewController 
@synthesize objData,usecaseTF,featureTF,priority,voteBtn; 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

-(void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    usecaseTF.text=objData.usecaseTF; 
    featureTF.text=objData.featureTF; 
    priority.text=objData.priority; 


} 

-(IBAction)voteBtnClk:(id)sender 
{ 
    if ([voteBtn.currentImage isEqual:@"BtnGreen.png"]) 
    { 
     [voteBtn setImage:[UIImage imageNamed:@"BtnBlack.png"] forState:UIControlStateNormal]; 
    } 
    else 
    { 
     [voteBtn setImage:[UIImage imageNamed:@"BtnGreen.png"] forState:UIControlStateNormal]; 

    } 
} 
- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

#import <UIKit/UIKit.h> 

@interface NewViewController : UIViewController<UITextFieldDelegate> 
{ 
    UITextField *currentTF; 
} 
@property(strong,nonatomic) IBOutlet UITextField *nameTF; 
@property(strong,nonatomic)IBOutlet UITextField *emailTF; 
@property(strong,nonatomic)IBOutlet UITextField *featureTF; 
@property(strong,nonatomic)IBOutlet UITextField *descpTF; 
@property(strong,nonatomic)IBOutlet UITextView *UsecaseTV; 
@property(strong,nonatomic)IBOutlet UIButton *HighBtn; 
@property(strong,nonatomic)IBOutlet UIButton *LowBtn; 
@property(strong,nonatomic)IBOutlet UIButton *MediumBtn; 

-(IBAction)sendRequestBtnClk:(id)sender; 
-(IBAction)RadioBtnHigh:(id)sender; 
-(IBAction)RadioBtnLow:(id)sender; 
-(IBAction)RadioBtnMedium:(id)sender; 
-(void)radioBtnClick; 
@end 
#import "NewViewController.h" 

@interface NewViewController() 

@end 

@implementation NewViewController 

@synthesize nameTF,emailTF,featureTF,descpTF,UsecaseTV,LowBtn,HighBtn,MediumBtn; 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    [email protected]"Did I Know This"; 
    currentTF=[[UITextField alloc]init]; 
    [ self radioBtnClick]; 
} 

-(IBAction)sendRequestBtnClk:(id)sender 
{ 

    if (nameTF.text.length==0) 
    { 
     [self showAlertMessage:@"Please enter Your Name"]; 
     // return NO; 
    } 
    else if (emailTF.text.length==0) 
    { 
     [self showAlertMessage:@"Please enter email ID"]; 

    } 
    if (emailTF.text.length==0) 
    { 
     [self showAlertMessage:@"Please enter email address"]; 

    } 
    else if ([self emailValidation:emailTF.text]==NO) 
    { 
     [self showAlertMessage:@"Please enter valid email address"]; 

    } 
    else if(featureTF.text.length==0) 
    { 
    [self showAlertMessage:@"Please Confirm the Feature title"]; 
    } 

} 
-(BOOL) emailValidation:(NSString *)emailTxt 
{ 
    NSString *emailRegex = @"[A-Z0-9a-z._%+-][email protected][A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; 
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; 
    return [emailTest evaluateWithObject:emailTxt]; 

} 

-(void)showAlertMessage:(NSString *)msg 
{ 
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Note" message:msg delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 
    [alert show]; 
} 

#pragma mark TextField Delegates 
- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    [currentTF resignFirstResponder]; 

return YES; 
} 
-(void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
currentTF = textField; 
[self animateTextField:textField up:YES]; 
} 

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
currentTF = textField; 

[self animateTextField:textField up:NO]; 
} 

-(void)animateTextField:(UITextField*)textField up:(BOOL)up 
{ 
int movementDistance = 0; // tweak as needed 

if (textField.tag==103||textField.tag==104||textField.tag==105||textField.tag==106) 
{ 
movementDistance = -130; 
} 

else if (textField.tag==107||textField.tag==108) 
{ 
movementDistance = -230; 
} 
else 
{ 
movementDistance = 00; 

} 
const float movementDuration = 0.3f; // tweak as needed 

int movement = (up ? movementDistance : -movementDistance); 

[UIView beginAnimations: @"animateTextField" context: nil]; 
[UIView setAnimationBeginsFromCurrentState: YES]; 
[UIView setAnimationDuration: movementDuration]; 
self.view.frame = CGRectOffset(self.view.frame, 0, movement); 
[UIView commitAnimations]; 
} 

-(void)radioBtnClick 
{ 
    if ([HighBtn.currentImage isEqual:@"radiobutton-checked.png"]) 
    { 


     [LowBtn setImage:[UIImage imageNamed:@"radiobutton-checked.png"] forState:UIControlStateNormal]; 
    [MediumBtn setImage:[UIImage imageNamed:@"radiobutton-unchecked.png"] forState:UIControlStateNormal]; 
     [HighBtn setImage:[UIImage imageNamed:@"radiobutton-unchecked.png"] forState:UIControlStateNormal]; 
    } 
    else 
    { 
     [LowBtn setImage:[UIImage imageNamed:@"radiobutton-unchecked.png"] forState:UIControlStateNormal]; 
     [HighBtn setImage:[UIImage imageNamed:@"radiobutton-checked.png"] forState:UIControlStateNormal]; 
     [MediumBtn setImage:[UIImage imageNamed:@"radiobutton-unchecked.png"] forState:UIControlStateNormal]; 
    } 
} 

-(IBAction)RadioBtnHigh:(id)sender 
{ 


     [LowBtn setImage:[UIImage imageNamed:@"radiobutton-checked.png"] forState:UIControlStateNormal]; 
     [HighBtn setImage:[UIImage imageNamed:@"radiobutton-unchecked.png"] forState:UIControlStateNormal]; 
    [MediumBtn setImage:[UIImage imageNamed:@"radiobutton-unchecked.png"] forState:UIControlStateNormal]; 
} 


-(IBAction)RadioBtnLow:(id)sender 
{ 


    [LowBtn setImage:[UIImage imageNamed:@"radiobutton-unchecked.png"] forState:UIControlStateNormal]; 
    [HighBtn setImage:[UIImage imageNamed:@"radiobutton-checked.png"] forState:UIControlStateNormal]; 
    [MediumBtn setImage:[UIImage imageNamed:@"radiobutton-unchecked.png"] forState:UIControlStateNormal]; 

} 
-(IBAction)RadioBtnMedium:(id)sender 
{ 
    [LowBtn setImage:[UIImage imageNamed:@"radiobutton-unchecked.png"] forState:UIControlStateNormal]; 
    [HighBtn setImage:[UIImage imageNamed:@"radiobutton-unchecked.png"] forState:UIControlStateNormal]; 
    [MediumBtn setImage:[UIImage imageNamed:@"radiobutton-checked.png"] forState:UIControlStateNormal]; 
} 





- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
#import <UIKit/UIKit.h> 

@interface CustomCellVC : UITableViewCell 
@property (strong,nonatomic) IBOutlet UIImageView *persnImage; 
@property (strong,nonatomic) IBOutlet UIButton *thumbImage; 
@property (strong,nonatomic) IBOutlet UIImageView *calenderImage; 
@property (strong,nonatomic) IBOutlet UIButton *voteImage; 
@property (strong,nonatomic) IBOutlet UIButton *selectImage; 
@property (strong,nonatomic) IBOutlet UILabel *publabel; 
@property (strong,nonatomic) IBOutlet UILabel *IdLabel; 
@property (strong,nonatomic) IBOutlet UILabel *decpLabel; 
@property (strong,nonatomic) IBOutlet UITextField *ansTF; 


@end 
#import "CustomCellVC.h" 

@implementation CustomCellVC 
@synthesize ansTF,persnImage,publabel,thumbImage,calenderImage,voteImage,selectImage,IdLabel,decpLabel; 
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 

@end 
@synthesize ObjFirstVC,objNavc; 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    ObjFirstVC=[[FirstVC alloc ]initWithNibName:@"FirstVC" bundle:nil]; 
    objNavc=[[UINavigationController alloc]initWithRootViewController:ObjFirstVC]; 
    [self.window addSubview:objNavc.view]; 
    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

#import <Foundation/Foundation.h> 

@interface DetailData : NSObject 
@property(strong,nonatomic)IBOutlet UITextField *usecaseTF; 
@property(strong,nonatomic)IBOutlet UITextView *featureTF; 
@property(strong,nonatomic)IBOutlet UILabel *priority; 
@property(strong,nonatomic)IBOutlet UIButton *voteBtn; 
@end 
+2

설명을 추가하십시오. 코드 붙여 넣기만으로 충분하지 않습니다. – DhruvJoshi

관련 문제