2013-01-03 3 views
1

안녕하세요 저는 프로그래밍 장면이 처음인데 lynda.com을 사용하여 소규모 프로젝트에서 기술과 실습을 배우고 있습니다. 편지에 대한 강사 지침을 따랐지 만 우리의 결과는 아주 다릅니다. NSMutable Array 내 코스의 "name"문자열을 표의 셀 제목으로 표시하고 싶지만 앱을로드 할 때 아무 것도 나타나지 않습니다. 우둔한 아이를 제발 도와주세요! 여기 Xcode : 테이블에 데이터 표시

내 클래스의 코드이며, 구현 파일은 내 속성 여기

#import "Class.h" 

@implementation Course 

@synthesize name,teacher,room; 

@end 

등을위한 synthesization 내 UITable 뷰 컨트롤러 클래스에 대한 코드가 포함

#import "ScheduleTableViewController.h" 

@interface ScheduleTableViewController() 

@end 

@implementation ScheduleTableViewController 

NSMutableArray *classes; 



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

- (void)viewDidLoad 
{ 


NSMutableArray *classes = [[NSMutableArray alloc]init]; 

Course *class = [[Course alloc]init]; 
[class setName:@"AP Psychology"]; 
[class setRoom:@"E203"]; 
[class setTeacher:@"Juiliette Forbes"]; 
[classes addObject:class]; 

[class setName:@"AP Literature"]; 
[class setTeacher:@"Kristen Holtz"]; 
[class setRoom:@"E207"]; 
[classes addObject:class]; 

[class setName:@"AP Physics"]; 
[class setTeacher:@"Peter Dalby"]; 
[class setRoom:@"D205"]; 
[classes addObject:class]; 

[super viewDidLoad]; 


} 

- (void)viewDidUnload 
{ 
[super viewDidUnload]; 

} 

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

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 


return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

return [classes count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"ClassCell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier:CellIdentifier]; 
      } 
Course *current = [classes objectAtIndex:indexPath.row]; 
[cell.textLabel setText:[current name]]; 

return cell; 
} 

어떤 도움이됩니다 잘 부탁드립니다. 그리고 잘하면 내가 알아서 할 수 있습니다.

+1

코드의 일부분이 올바르지 않습니다. '#import "Class.h" @ 구현 과정 @synthesize name, teacher, room; @ end' import Class.h 및 구현 과정? 또한 대리인을 제외하고 테이블 뷰의 ** 데이터 소스 **를 설정해야합니다. – esh

+1

viewdidLoad()에서 redeclaration 데이터 소스 배열 클래스를 제거하면 코드가 완벽하게 작동합니다. – Vinodh

+0

파일은 class.h라고 불리지 만 클래스의 이름을 "class"에서 변경해야합니다. 왜냐하면 그 코드가 기초 코드와 충돌하여 "course"로 변경 되었기 때문입니다. 데이터 소스의 재 선언에 관해서는 실제로 그것이 무엇인지 알지 못한다고 생각합니다. 내가 말했듯이 미안해 내가 좀 새로운거야 – Hammy

답변

0

탭 식별자를 올바르게 설정했는지 확인하십시오. 르 셀.

이렇게하려면 스토리 보드 편집기를 열고 테이블보기로 이동하십시오. 프로토 타입 셀을 클릭하고 유틸리티 패널을 엽니 다. "Identifier"가 "ClassCell"인지 확인하십시오.

다음으로 ViewController가 UITableViewController이고 UITableViewDelegate 프로토콜을 구현하는지 확인하십시오. 네가이 일을했다면 분명하지 않다.

귀하의 ScheduleTableViewController.h이 있어야 할 무엇인가 : 또한

#import <UIKit/UIKit.h> 

@interface ScheduleTableViewController : UITableViewController <UITableViewDelegate> 
// code 
@end 

, 내가 여기를 발견 : * 클래스 이후

NSMutableArray *classes = [[NSMutableArray alloc]init]; 

Course *class = [[Course alloc]init]; 
[class setName:@"AP Psychology"]; 
[class setRoom:@"E203"]; 
[class setTeacher:@"Juiliette Forbes"]; 
[classes addObject:class]; 

[class setName:@"AP Literature"]; 
[class setTeacher:@"Kristen Holtz"]; 
[class setRoom:@"E207"]; 
[classes addObject:class]; 

[class setName:@"AP Physics"]; 
[class setTeacher:@"Peter Dalby"]; 
[class setRoom:@"D205"]; 
[classes addObject:class]; 

는 물론 개체에 대한 포인터, 당신은 실제로했습니다 그런 다음 속성을 편집하고 배열에 다시 추가합니다. 다음과 같이 여러 클래스 객체를 작성하십시오.

Course *class1 = [[Course alloc] init]; 
// set properties 
Course *class2 = [[Course alloc] init]; 
// set properties 
Course *class3 = [[Course alloc] init]; 
// set properties 
[classes addObjects:class1, class2, class3, nil]; 
+0

내 재사용 식별자가 좋고 나의 위임 프로토콜도 좋다. 내 배열과 더 관련이 없으며 배열에서 가져온 것이 아닌 텍스트를 추가하려고 시도 할 때 내 테이블과 더 관련이 있다고 생각합니다. 클래스 포인터에 대한 제안을 가져 주셔서 감사합니다. 나는 똑같은 생각을했지만 비디오의 한 사람은 여러 번 재사용되는 단일 포인터로이 작업을 수행 할 수있었습니다. – Hammy

+0

Vinodh가 데이터 소스 배열을 다시 선언하지 않는다고 말한 것은 두번 입력 한 것입니다 : NSMutableArray * classes; 한 번만 선언하면됩니다.따라서 다음 줄을 변경하십시오. NSMutableArray * classes = [[NSMutableArray alloc] init]; to : classes = [[NSMutableArray alloc] init]; (편집 : 이것은 배열이 초기화되지 않았기 때문에 아무것도 채우지 않는다는 것을 의미합니다. 대신 동일한 것을 호출하는 다른 변수를 초기화했습니다.) –

관련 문제