다른 뷰어에서로드 한 배열을 가져 와서 TableViewController가 아닌 UITableView에 배치하려고합니다. 어떻게해야할지 모르겠다. 지금은이 코드가 있습니다배열을 TableViewController가 아닌 UITableView로로드하는 방법
CRHCommentSection.m을
#import "CRHCommentSection.h"
#import "CRHViewControllerScript.h"
@interface CRHCommentSection()
@end
@implementation CRHCommentSection
@synthesize observationTable;
NSArray *myArray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
myArray = [CRHViewControllerScript theArray];
NSLog(@"%@", myArray);
//NSArray* paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:1]];
//[observationTable insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
NSLog(@" in method 1");
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@" in method 2");
// Return the number of rows in the section.
return [myArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@" in method 3");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [myArray objectAtIndex:indexPath.row];
return cell;
}
CRHCommentSection.h
#import <UIKit/UIKit.h>
@interface CRHCommentSection : UIViewController
@property (weak, nonatomic) IBOutlet UITableView *observationTable;
@end
게시 한 코드를 읽고, 나는 당신이 갖고있는 것과 당신이 원하는 것의 차이에 대해 명확하지 않습니다. –
이것을 실행하면 빈 테이블이 생깁니다. – Craig