n.e*_*ind 0 iphone cocoa-touch objective-c uitextview
我在UITextView中尝试计算返回(\n)时遇到了麻烦.正如你很快就会意识到的那样,我是一个血腥的初学者,这是我对你所提出的理论的理论,但是存在很多差距......
- (IBAction)countReturns:(id)sender {
int returns;
while ((textView = getchar()) != endOfString [if there is such a thing?])
{
if (textView = getchar()) == '\n') {
returns++;
}
}
NSString *newText = [[NSString alloc] initWithFormat:@"Number of returns: %d", returns];
numberReturns.text = newText;
[newText release];
}
Run Code Online (Sandbox Code Playgroud)
我在这里检查了其他问题,但人们通常(在我看来)丢失了一些我不明白的细节.任何帮助将非常感谢!谢谢你的耐心.
你可以简单
UITextView *theview; //remove this line, and change future theview to your veiw
NSString *thestring; //for storing a string from your view
int returnint = 0;
thestring = [NSString stringWithFormat:@"%@",[theview text]];
for (int temp = 0; temp < [thestring length]; temp++){ //run through the string
if ([thestring characterAtIndex: temp] == '\n')
returnint++;
}
Run Code Online (Sandbox Code Playgroud)