如何获取字符串的第n个字符?我尝试了托架([])访问器没有运气.
var string = "Hello, world!"
var firstChar = string[0] // Throws error
Run Code Online (Sandbox Code Playgroud)
错误:'subscript'不可用:不能使用Int下标String,请参阅文档注释以供讨论
我将此方法添加到我的代码中以格式化文本字段.我正在使用下面的代码尝试添加方法,但它无法正常工作,我做错了什么?
.h文件
NSString* phone_;
UITextField* phoneFieldTextField;
@property (nonatomic,copy) NSString* phone;
Run Code Online (Sandbox Code Playgroud)
.m文件
@synthesize phone = phone_;
ViewDidLoad{
self.phone = @"";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
// Make cell unselectable and set font.
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.font = [UIFont fontWithName:@"ArialMT" size:13];
if (indexPath.section == 0) {
UITextField* tf = nil;
switch ( indexPath.row ) {
case 3: {
cell.textLabel.text = @"Phone" ;
tf = phoneFieldTextField = [self makeTextField:self.phone placeholder:@"xxx-xxx-xxxx"];
phoneFieldTextField.keyboardType …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我将电话号码作为用户的输入.号码应采用美国格式.我想动态地显示它(555)-888-888.例如,当用户在达到4位时开始输入数字时,它显示如下的数字(555)-4,依此类推.我试过replaceString方法,但我发现它不起作用.
character ×1
collections ×1
ios ×1
iphone ×1
methods ×1
nsstring ×1
string ×1
swift ×1
uitableview ×1