如何将TextView内的文本转换为NSString?

时间:2011-04-17 03:03:50

标签: iphone objective-c textview

如何将TextView中的文本转换为NSString?

NSString *path = tabels.text;
NSData *dataFromPath = [NSData dataWithContentsOfFile:path];

UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];

if(printController && [UIPrintInteractionController canPrintData:dataFromPath]) {

    printController.delegate = self;

    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = [path lastPathComponent];
    printInfo.duplex = UIPrintInfoDuplexLongEdge;
    printController.printInfo = printInfo;
    printController.showsPageRange = YES;
    printController.printingItem = dataFromPath;

    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        if (!completed && error) {
            NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
        }
    };

    [printController presentAnimated:YES completionHandler:completionHandler];

} 

1 个答案:

答案 0 :(得分:3)

您可以使用UITextView属性访问text内的文字。例如:

NSString *myText = aTextView.text;