调用子视图

时间:2013-12-30 05:24:58

标签: ios

#import "sideTableViewController.h"

@interface sideTableViewController ()
{

    NSArray *colours;
}
@end

@implementation sideTableViewController
@synthesize colorNames;
@synthesize sideTableView;
- (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.
    self.sideTableView.delegate= self;
    self.sideTableView.dataSource=self;
    colorNames = [NSArray arrayWithObjects:@"Archie",@"Sethi",@"Rajan" ,@"Deepak" ,nil];

}
- (NSInteger)sideTableView:(UITableView *)sideTableView numberOfRowsInSection:(NSInteger)section    
{
    return [colorNames count];
}

- (UITableViewCell *)sideTableView:(UITableView *)sideTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;

    cell = [sideTableView dequeueReusableCellWithIdentifier:@"MyCell"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];

    }

    cell.textLabel.text =[colorNames objectAtIndex:indexPath.row];
    // NSLog(@"the indexpath is %@",indexPath);
    return cell;

  }

- (void)sideTableView:(UITableView *)sideTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell = [sideTableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[sideTableView deselectRowAtIndexPath:indexPath animated:YES];

}

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

@end

这是头文件......

#import <UIKit/UIKit.h>

@interface sideTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
    NSArray *colorNames;
}
@property (strong, nonatomic) IBOutlet UITableView *sideTableView;
-(IBAction)showMessage;
@property (nonatomic, retain) NSArray *colorNames;

@end

我正在尝试将图像作为现有tableview的背景。 我得到一个例外:[sideTableViewController tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例0x7593640

请帮助我成为IOS编程的新手!

1 个答案:

答案 0 :(得分:0)

这段代码可以帮助您简单地将以下代码添加到

之上
- (NSInteger)sideTableView:(UITableView *)sideTableView numberOfRowsInSection:(NSInteger)section

添加此代码

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}