我已经看过很多次这里被问过,但没有一个解决方案适合我.这是我的代码片段:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellClassName = @"DemoTableViewCell_sched";
DemoTableViewCell_sched *cell = [tableView dequeueReusableCellWithIdentifier:CellClassName];
if (cell == nil)
{
NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil];
cell = [topLevelItems objectAtIndex:0];
}
cell.fooData = [self.bugs objectAtIndex:indexPath.row];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
然后我进来了 ViewDidLoad
cellLoader = [UINib nibWithNibName:@"DemoTableViewCell_sched" bundle:[NSBundle mainBundle]];
Run Code Online (Sandbox Code Playgroud) 我以某种方式错误地使用stringByReplacingCharactersInRange,但我无法理解如何.我的目标是将一个角色替换为另一个角色NSString.我做了很多次,但经过两次更换后,它从NSString的末尾开始切割,我不想这样做.这是我的代码.
NSRange firstCharRange = NSMakeRange(mi, mi); // mi is an int, indicating the index of the replaced char
myword = [myword stringByReplacingCharactersInRange:firstCharRange withString:bb.titleLabel.text]; // myword is the string
Run Code Online (Sandbox Code Playgroud)
最初myword是@"RRRRRRRR",在替换第一个字符串后就成了
eRRRRRRR
Run Code Online (Sandbox Code Playgroud)
然后
egRRRRRR
Run Code Online (Sandbox Code Playgroud)
然后
eghRRRR // why did cut off the last character?
Run Code Online (Sandbox Code Playgroud)