W scenorysie dodałem widok tabeli do kontrolera widoku, Ctrl przeciągnąłem widok TableView do Viewcontroller i połączono "delegate" i "datasource". W pliku (h) dodałem <UITableViewDataSource,UITableViewDelegate>
, ale po uruchomieniu aplikacji pojawia się błąd SIGABRT (?) I aplikacja ulega awarii. Co powinienem zrobić?Jak korzystać z TableView wewnątrz viewcontroller?
12
A
Odpowiedz
19
Do tej pory wystarczy wprowadzić implementację UITableViewDataSource i UITableViewDelegate w pliku implementacji.
Wymagane funkcje są następujące;
- (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
Dzięki, bardzo mi to pomogło! – b3rge
Powiązane problemy
- 1. Swift: TableView w ViewController
- 2. Jak odświeżyć dane w Tableview z innej ViewController w Swift
- 3. Widok tabeli wewnątrz widoku, wewnątrz viewcontroller. Najlepszy sposób to zrobić?
- 4. Ładowanie ViewController wewnątrz widoku kontenera
- 5. Jak korzystać z funkcji wewnątrz łańcucha?
- 6. Jak korzystać z Wybierz wewnątrz przycisku?
- 7. Odrzuć Modal NavigationController od pchniętego ViewController wewnątrz
- 8. Prezentacja storyboardu ViewController z innego ViewController
- 9. UITableViewController vs TableView
- 10. Jak korzystać Recyclerview wewnątrz Scrollview
- 11. Jak korzystać z funkcji prepareForSegue w trybie szybkiego?
- 12. UITextView wewnątrz UITableViewCell, jak zrezygnować firstResponder textview podczas przewijania tableView?
- 13. IOS: Tableview metody Delegat dwa tableview
- 14. Jak dodać pull tableview do odświeżania danych wewnątrz uitableview
- 15. Przechodzenie z UITableViewCell do innego ViewController
- 16. Swipe Usuwanie Tableview Row
- 17. Jak korzystać z frameworka Hero?
- 18. Jak korzystać z modułu Architecture Components ViewModel wewnątrz adaptera RecyclerView?
- 19. Jak korzystać z tymczasowego taggera HeidelTime wewnątrz projektu Java?
- 20. Haskell - Jak mogę korzystać z czystych funkcji wewnątrz funkcji IO?
- 21. Jak korzystać z mapy google V2 wewnątrz fragmentu?
- 22. Jak korzystać z Server.MapPath wewnątrz projektu biblioteki klas
- 23. Jak korzystać z funkcji setInterval wewnątrz pętli for
- 24. Jak korzystać z Html.EditorFor() (i innych) wewnątrz niestandardowego pomocnika HTML?
- 25. Jak korzystać z operatora trójskładnikowego wewnątrz interpolowanego ciągu?
- 26. Jak korzystać z dequeueReusableCellWithIdentifier w Swift?
- 27. Zatrzymaj wykonywanie GCD, gdy pojawi się ViewController
- 28. Uzyskiwanie wartości appdelegate z viewcontroller
- 29. TableView z dwoma instancjami NSFetchedResultsController
- 30. Metoda wywołania z innego ViewController
błąd th: #import #import "AppDelegate.h" Int główne (Int ARGC char * argv []) { @ autoreleasepool { return UIApplicationMain (argc, argv, zero, NSStringFromClass ([klasa AppDelegate])); } } –
b3rge
Czy zaimplementowałeś wymagane metody UITableViewDataSource? – ColdLogic
Nie, nie mam @ColdLogic – b3rge