Trong bảng phân cảnh tôi đã thêm chế độ xem bảng vào bộ điều khiển chế độ xem của mình, tôi đã ctrl kéo TableView đến Viewcontroller và kết nối "delegate" và "datasource". Trong tập tin (.h) tôi đã thêm <UITableViewDataSource,UITableViewDelegate>
nhưng khi tôi chạy ứng dụng, tôi chỉ gặp lỗi SIGABRT (?) Và ứng dụng gặp sự cố. Tôi nên làm gì?Làm thế nào để sử dụng TableView bên trong viewcontroller?
12
A
Trả lời
19
Cho đến giờ rất tốt, bạn chỉ cần triển khai UITableViewDataSource và UITableViewDelegate trong tệp triển khai của bạn.
Các chức năng bắt buộc như sau;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [regions count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Number of rows is the number of time zones in the region for the specified section.
Region *region = [regions objectAtIndex:section];
return [region.timeZoneWrappers count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
// The header for the section is the region name -- get this from the region at the section index.
Region *region = [regions objectAtIndex:section];
return [region name];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyReuseIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]];
}
Region *region = [regions objectAtIndex:indexPath.section];
TimeZoneWrapper *timeZoneWrapper = [region.timeZoneWrappers objectAtIndex:indexPath.row];
cell.textLabel.text = timeZoneWrapper.localeName;
return cell;
}
+0
Cảm ơn, điều đó đã giúp tôi rất nhiều! – b3rge
Các vấn đề liên quan
- 1. Sử dụng tableView và ViewController hiện có với UISearchDisplayController
- 2. Nhúng ViewController bên trong một ViewController khác trong Storyboard
- 3. Làm thế nào để lập trình tải một viewController khác từ một ViewController trong MonoTouch
- 4. Làm cách nào để quản lý 2 lần xem bảng trong 1 viewController?
- 5. Làm thế nào để bạn tạo một TableView tĩnh rất dài bằng cách sử dụng Storyboard?
- 6. Làm thế nào để tùy chỉnh tableView Section View - iPhone
- 7. Làm thế nào để đẩy viewcontroller (view controller)?
- 8. Làm thế nào để đặt giữa activityindicator của một tableview
- 9. Làm thế nào để thiết kế riêng biệt UIView bên ngoài của bất kỳ ViewController trong Storyboard?
- 10. Làm thế nào để luôn luôn có thể nhìn thấy cuộn của Tableview trong Obj c?
- 11. Làm thế nào để tương tác với UITableView trong UIViewController?
- 12. Làm thế nào để thêm NavigationBar (không có NavigationController) và SearchBar vào một TableView
- 13. Làm thế nào để bạn sử dụng "C" bên ngoài để gọi hàm C++ trong C
- 14. Làm thế nào để sử dụng grails.plugin.location?
- 15. Làm thế nào để sử dụng tên biến bên trong các chữ trong Emacs Lisp?
- 16. làm thế nào để thay đổi màu nền của viewController trong mục tiêu-c
- 17. Nhận tableView: heightForRowAtIndexPath: để xảy ra sau khi tableView: cellForRowAtIndexPath :?
- 18. UITableViewController vs TableView
- 19. Làm thế nào để vô hiệu hóa sắp xếp lại cột trong một TableView JavaFX2?
- 20. Làm thế nào để sử dụng unicode bên trong một chuỗi xpath? (UnicodeEncodeError)
- 21. Làm thế nào để tìm div bên trong div khác bằng cách sử dụng HtmlUnit?
- 22. Làm thế nào để sử dụng thử nghiệm bên ngoài trong Mã R
- 23. Làm thế nào để đơn vị phương pháp thử nghiệm sử dụng System.Web.Security.Membership bên trong?
- 24. Sử dụng SQLAlchemy ORM bên trong một di cư Alembic: làm thế nào để tôi?
- 25. Làm thế nào để sử dụng các API bên ngoài trong Rails?
- 26. Làm thế nào để sử dụng máy chủ Tomcat bên ngoài trong Netbeans trên Linux?
- 27. Làm thế nào để sử dụng mã C# bên trong <% ... %> thẻ trên trang asp.net?
- 28. Làm thế nào để sử dụng PrimeFaces p: droppable bên trong datatable?
- 29. Làm thế nào để sử dụng CSS di chuột bên trong html-tag?
- 30. Làm thế nào để sử dụng một hàm bên trong chuỗi?
lỗi thứ: #import #import "AppDelegate.h" int main (int argc, char * argv []) { @ autoreleasepool { trả về UIApplicationMain (argc, argv, nil, NSStringFromClass ([Lớp AppDelegate])); } } –
b3rge
Bạn đã triển khai các phương thức được yêu cầu của UITableViewDataSource chưa? – ColdLogic
Không, tôi không @ColdLogic – b3rge