簡體   English   中英

iOS:為什么在自定義TableViewCell內寫入此文本字段的文本看起來不可讀

[英]iOS: Why is the text written into this textfield within a custom TableViewCell not appearing to be readable

所以我有一個位於視圖控制器內的視圖中的tableview。

然后,我希望表視圖具有單元格,這些單元格的左側帶有文本標簽,右側帶有文本字段,以便用戶可以在此文本字段中輸入數據。

我創建了一個自定義類tableviewcell,其外觀如下:

#import <UIKit/UIKit.h>

@interface TableViewCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UITextField *textField;


@end

這是tableview和單元格所在的視圖的控制器;

頭文件:

#import <UIKit/UIKit.h>

@interface SignUpViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UITableView *Table;

@property (strong, nonatomic) NSMutableArray *SignUpTableNames;

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath;

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section;





@end

以及將我自己的單元格類型添加到此視圖/表的兩種方法:

- (TableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdent =@"Cell";
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdent forIndexPath:indexPath];
    //cell.textLabel.text =@"t";
    //NSString *s = [self.SignUpTableNames objectAtIndex:indexPath.row];
    cell.textLabel.text = (NSString *)[self.SignUpTableNames objectAtIndex:indexPath.row];
    cell.textField.placeholder = @"h";
    cell.textField.textColor = [UIColor greenColor];
    if (indexPath.row ==4)
    {
        cell.textField.secureTextEntry = YES;
    }

    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;

}

從SignUpTableName NSMutableArray更新cell.textLabel.text可以很好,但是cell.textField實例似乎是一個問題。 該文本字段是不可見的,並且我不確定它是否存在。 如果我點擊文本字段應該在的位置,我會得到一個鍵盤並且可以嘗試在該字段中鍵入一些數據,但是,實際上我在屏幕上看不到該文本。

這有什么問題,為什么我不能在自定義單元格內的文本字段中看到該文本?

非常感謝,最誠摯的問候,

克里斯

為了澄清起見,我還在xcode的圖形用戶界面中將單元格標識符設置為“單元格”,還通過圖形用戶在表格視圖和視圖的視圖控制器之間設置了委托和數據源連接。 xcode的接口。

在TableViewCell.m中添加此函數,並確保NSLog正在打印,如果沒有將此函數中的內容復制到您使用的任何初始化函數中

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{

    _textField=[[UITextField alloc]initWithFrame:CGRectMake(70, 0, 150, 40)];
    [self addSubview:_textField];
    NSLog(@"init with style should be called");//this should be printed in log

}
return self;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM