如何为 UITableView 建立索引?

发布于 2024-12-22 09:07:53 字数 3883 浏览 3 评论 0原文

我在 UITableView 的索引中较新。 我有一些演示数据,例如,

tableDataArray = [[NSMutableArray alloc] init];

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:[NSString stringWithFormat:@"Thomas Cook"] forKey:@"Name"];
[dict setObject:[NSString stringWithFormat:@"Dean"] forKey:@"Position"];
[dict setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict setObject:[NSString stringWithFormat:@"67-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict];

NSMutableDictionary *dict1 = [[NSMutableDictionary alloc] init];
[dict1 setObject:[NSString stringWithFormat:@"John Appleseed"] forKey:@"Name"];
[dict1 setObject:[NSString stringWithFormat:@"Department of accounting"] forKey:@"Position"];
[dict1 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict1 setObject:[NSString stringWithFormat:@"45-876-65433"] forKey:@"PhoneNo"];
 [tableDataArray addObject:dict1];

NSMutableDictionary *dict2 = [[NSMutableDictionary alloc] init];
[dict2 setObject:[NSString stringWithFormat:@"Amar Smith"] forKey:@"Name"];
[dict2 setObject:[NSString stringWithFormat:@"Department of Human Resource"] forKey:@"Position"];
[dict2 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict2 setObject:[NSString stringWithFormat:@"54-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict2];

NSMutableDictionary *dict3 = [[NSMutableDictionary alloc] init];
[dict3 setObject:[NSString stringWithFormat:@"Mary Cold"] forKey:@"Name"];
[dict3 setObject:[NSString stringWithFormat:@"HOD of Computer Department"] forKey:@"Position"];
[dict3 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict3 setObject:[NSString stringWithFormat:@"52-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict3];

NSMutableDictionary *dict4 = [[NSMutableDictionary alloc] init];
[dict4 setObject:[NSString stringWithFormat:@"John Jobs"] forKey:@"Name"];
[dict4 setObject:[NSString stringWithFormat:@"Department of Physics"] forKey:@"Position"];
[dict4 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict4 setObject:[NSString stringWithFormat:@"12-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict4];

NSMutableDictionary *dict5 = [[NSMutableDictionary alloc] init];
[dict5 setObject:[NSString stringWithFormat:@"Clark Kristan"] forKey:@"Name"];
[dict5 setObject:[NSString stringWithFormat:@"Contact Person"] forKey:@"Position"];
[dict5 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict5 setObject:[NSString stringWithFormat:@"65-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict5];

所以,我想创建索引 UITableView。我的 UITableView 委托和数据源方法与上述各自的数据格式将如何?

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

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
}

谢谢

i newer in Indexing of UITableView.
I have some demo data like,

tableDataArray = [[NSMutableArray alloc] init];

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:[NSString stringWithFormat:@"Thomas Cook"] forKey:@"Name"];
[dict setObject:[NSString stringWithFormat:@"Dean"] forKey:@"Position"];
[dict setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict setObject:[NSString stringWithFormat:@"67-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict];

NSMutableDictionary *dict1 = [[NSMutableDictionary alloc] init];
[dict1 setObject:[NSString stringWithFormat:@"John Appleseed"] forKey:@"Name"];
[dict1 setObject:[NSString stringWithFormat:@"Department of accounting"] forKey:@"Position"];
[dict1 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict1 setObject:[NSString stringWithFormat:@"45-876-65433"] forKey:@"PhoneNo"];
 [tableDataArray addObject:dict1];

NSMutableDictionary *dict2 = [[NSMutableDictionary alloc] init];
[dict2 setObject:[NSString stringWithFormat:@"Amar Smith"] forKey:@"Name"];
[dict2 setObject:[NSString stringWithFormat:@"Department of Human Resource"] forKey:@"Position"];
[dict2 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict2 setObject:[NSString stringWithFormat:@"54-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict2];

NSMutableDictionary *dict3 = [[NSMutableDictionary alloc] init];
[dict3 setObject:[NSString stringWithFormat:@"Mary Cold"] forKey:@"Name"];
[dict3 setObject:[NSString stringWithFormat:@"HOD of Computer Department"] forKey:@"Position"];
[dict3 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict3 setObject:[NSString stringWithFormat:@"52-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict3];

NSMutableDictionary *dict4 = [[NSMutableDictionary alloc] init];
[dict4 setObject:[NSString stringWithFormat:@"John Jobs"] forKey:@"Name"];
[dict4 setObject:[NSString stringWithFormat:@"Department of Physics"] forKey:@"Position"];
[dict4 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict4 setObject:[NSString stringWithFormat:@"12-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict4];

NSMutableDictionary *dict5 = [[NSMutableDictionary alloc] init];
[dict5 setObject:[NSString stringWithFormat:@"Clark Kristan"] forKey:@"Name"];
[dict5 setObject:[NSString stringWithFormat:@"Contact Person"] forKey:@"Position"];
[dict5 setObject:[NSString stringWithFormat:@"[email protected]"] forKey:@"Email"];
[dict5 setObject:[NSString stringWithFormat:@"65-876-65433"] forKey:@"PhoneNo"];
[tableDataArray addObject:dict5];

So , i want to create index UITableView. How will be my UITableView delegate and datasource methods with respective above data format?

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

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
}

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

任谁 2024-12-29 09:07:53

您需要创建一个要在索引列表中显示的标题数组,并在 (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { } 和此 (NSInteger) 中返回该数组)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { } 只需返回索引。

了解更多信息请阅读 apples文档-
http://developer.apple.com/库/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html

You need to create an array of titles that you want to show in your index list and return that array in (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { } and in this (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { } just return the index.

for more info read apples doc -
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html

橘虞初梦 2024-12-29 09:07:53

有一篇关于 UITableView 索引的非常精彩的文章。

这是它的链接。

http://www.iphonedevcentral.com/indexed-uitableview-tutorial/

There is a very sweet article about the UITableView indexing.

here is the link for it.

http://www.iphonedevcentral.com/indexed-uitableview-tutorial/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文