uitableview كمظهر فرعي؟
-
30-09-2019 - |
سؤال
هل هذا ممكن؟ أريد فقط طاولة صغيرة في وجهة نظري الحالية ... إليك ما أحاول القيام به:
.h ملف
#import <UIKit/UIKit.h>
@interface IngredientsRootView : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView *ingredientsTable;
}
@property (nonatomic, retain) UITableView *ingredientsTable;
@end
.
ingredientsTable = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, 300, 300) style:UITableViewStylePlain];
[ingredientsTable setDelegate:self];
[ingredientsTable setDataSource:self];
[self.view addSubview:ingredientsTable];
لا يعطل التطبيق ، لكنه لا يعرض جدولًا. في الوقت الحالي ، قمت فقط بتعيين كل شيء بالتأكيد حسب:
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 10;
}
// 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] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = @"Hello";
return cell;
}
ما الخطأ الذي افعله؟ شكرًا
المحلول
حاول الاتصال -reloadData
في عرض الجدول بعد إضافته كقصة فرعية.
أيضا ، كيف يتم إعداد العرض؟ هل تم إنشاؤه في XIB أو عبر -loadView
?
نصائح أخرى
هل تذكرت إضافة [window addSubview:[IngredientsRootView view]];
إلى مندوب التطبيق الخاص بك؟
وبالمناسبة ، بدلاً من الوراثة من UiviewController ، يمكنك فقط أن ترث من UIlitableViewController وستحصل على كل هذه الوظائف لك بدون رمز إضافي.
لا تنتمي إلى StackOverflow