我正在为iPad和iPhone制作一个应用程序。在您需要登录的第一个屏幕中,此方法有效。但是接下来我进入下一个屏幕,女巫是一个tableview。我希望此视图是iPad或iPhone上adresbook的名称(名字和姓氏)。

我得到了tableview,但是它是空的。有人可以帮我吗?

这是我的控制器(.m,我不需要编辑.h):

#import "TableViewController.h"
#import "ViewController.h"
#import "AddressBook/AddressBook.h"

@interface TableViewController ()
@end

@implementation TableViewController
{
NSMutableArray *ListOfItems;
}

@synthesize tblContacts;

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

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

- (void)viewDidUnload
{
[self setTblContacts:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}

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

- (IBAction)Back:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}

- (void)ListContacts{
/*ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );

for ( int i = 0; i < nPeople; i++ )
{
    ABRecordRef ref = CFArrayGetValueAtIndex( allPeople, i );
    UITableView ContactList
} */

ListOfItems = [[NSMutableArray alloc] init];

[ListOfItems addObject:@"Iceland"];
[ListOfItems addObject:@"Greenland"];
[ListOfItems addObject:@"Switzerland"];
[ListOfItems addObject:@"Norway"];
[ListOfItems addObject:@"New Zealand"];
[ListOfItems addObject:@"Greece"];
[ListOfItems addObject:@"Rome"];
[ListOfItems addObject:@"Ireland"];

self.navigationItem.title = @"Countries";
}

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

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section         {
return [ListOfItems count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithFrame:CGRectZero   reuseIdentifier:CellIdentifier];
}

// Set up the cell...
NSString *cellValue = [ListOfItems objectAtIndex:indexPath.row];
cell.text = cellValue;

return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}

@end


请注意,我尝试用一​​些硬编码值填充表格。但是,我的桌子仍然空着。请帮忙。

最佳答案

#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
@interface AddressBookViewController: UIViewController <ABPeoplePickerNavigationControllerDelegate> {}
-(IBAction) btnClicked:(id)sender;
@end


这是AddressBook api,用于从您自己的应用程序访问通讯录应用程序。也许您可以使用它,它比实现自己的UITableView和所有控件要快得多。

希望能帮助到你。

08-06 04:09
查看更多